如何在使用MsBuild构建多个配置时仅构建已修改的项目

时间:2013-10-24 19:06:07

标签: visual-c++ msbuild msbuild-task incremental-build

我有一个构建许多项目的解决方案。其中一些项目生成DLL用于在其他开发团队之间进行再分配(用于集成)。我们自己的应用程序使用这些相同的DLL,它们主要经过修改和更新,以便维护此应用程序。 我们遇到的问题是,有时会将不需要的依赖项添加到我们提供给第三方的DLL中。因此,我们在visual studio解决方案中创建了一个新配置,它只构建我们提供给第三方的DLL。通过构建此配置,我们可以确保在为这些项目添加任何新依赖项时,我们的gated-checkin将失败。

<!-- Build only the Database Access provider DLLs, if a new, unwanted dependency is added, this MsBuild task will fail -->
<Message Text="Build Database Access Providers"/>
<MSBuild Condition="'$(Configuration)'=='Release'" Properties="Configuration=Database Providers Release; Platform=Mixed Platforms" Projects="@(MySolution)" Targets="Build" BuildInParallel="$(BuildInParallel)" />

<!-- ... -->
<!-- Build all the projects in the solution -->
<MSBuild Properties="Configuration=$(Configuration); Platform=Mixed Platforms" Projects="@(MySolution)" Targets="Build" BuildInParallel="$(BuildInParallel)" />

“数据库提供程序发布”配置在项目的“发布”配置中构建每个必需的项目。

因为第一次调用MsBuild在Release配置中构建了各个项目,而完整版本也在Release配置中构建了各个项目,我们认为“Build”目标会检测到构建输出是最新的,当我们执行对MsBuild的第二次调用时,第二次跳过重建这些项目。但是,MsBuild脚本将始终在第二次调用MsBuild任务时重建项目。这会增加我们的构建时间并影响我们构建的代码度量标准(例如,构建警告的数量会增加,因为会报告两次相同的警告)。

如果我只是整个调用解决方案两次(在解决方案级别使用相同的构建配置),MsBuild将正确跳过所有解决方案项(即,它执行项目的增量构建)。 E.g:

<!-- Build all the projects in the solution -->
<MSBuild Properties="Configuration=$(Configuration); Platform=Mixed Platforms" Projects="@(MySolution)" Targets="Build" BuildInParallel="$(BuildInParallel)" />
<!— This 2nd build will skip every project as MsBuild detects the projects have been built. -->
<MSBuild Properties="Configuration=$(Configuration); Platform=Mixed Platforms" Projects="@(MySolution)" Targets="Build" BuildInParallel="$(BuildInParallel)" />

如果我直接在Visual Studio中运行2个不同的构建配置,它将正确检测到已经构建了各种项目,并将跳过第二次重建它们(即vcxprojs的增量构建设置是正确的。 )

有没有办法使用MsBuild构建2个解决方案配置(其中每个解决方案配置使用相同的项目配置)并让MsBuild跳过在第二个构建中遇到第一个构建时已经构建的项目?

0 个答案:

没有答案