1

我有一个构建多个项目的解决方案。其中一些项目会生成 DLL,以便在其他开发团队中重新分发(用于集成)。这些相同的 DLL 由我们自己的应用程序使用,它们主要是为了维护该应用程序而修改和更新的。我们遇到了一个问题,有时会在我们提供给第三方的 DLL 中添加不需要的依赖项。因此,我们在 Visual Studio 解决方案中创建了一个新配置,该配置仅构建我们提供给第三方的 DLL。通过构建此配置,我们能够确保如果为这些项目添加任何新依赖项,我们的门控签入将失败。

<!-- 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)" />

“Database Providers Release”配置在项目的“Release”配置中构建每个所需的项目。

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

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

<!-- 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 在第 2 个构建中遇到它们时跳过第一个构建中已经构建的项目?

4

0 回答 0