让MSBuild只构建需要构建的目标

Joh*_*ohn 9 msbuild dependencies

长话短说,我们遇到了多种解决方案,它们之间有汇编参考.过去,我们必须以正确的顺序构建这些解决方案,以便正确构建我们的依赖项.

我正在尝试通过使用MSBuild任务来首先在依赖解决方案上恢复nuget,然后为您构建依赖项,即:

<Target Name="BeforeBuild" Condition="'$(Configuration)'=='Debug'">
    <Message Importance="high" Text="Kicking off internal dependency build for $(MSBuildProjectName) in Configuration=$(Configuration), Platform=$(Platform), OutDir=$(OutDir)" />
    <!--Build the dependencies-->
    <Message Importance="high" Text="Restoring MyDependencyProject NuGet External Packages..." />
    <Exec Command="..\..\bin\nuget.exe restore ..\MyProject\MyDependencyProject\MyDependencyProject.sln" />
    <Message Importance="high" Text="Building MyDependencyProject dependency..." />
    <MSBuild Projects="..\MyProject\MyDependencyProject\MyDependencyProject\MyDependencyProject.csproj" Targets="Build" Properties="Configuration=$(Configuration)" />
    <Message Importance="high" Text="Building MyDependencyProject2 dependency..." />
    <MSBuild Projects="..\MyProject\MyDependencyProject\MyDependencyProject\MyDependencyProject2.csproj" Targets="Build" Properties="Configuration=$(Configuration)" />
</Target>
Run Code Online (Sandbox Code Playgroud)

这很棒!过去是我们必须打开和构建的7(!)单独解决方案,现在压缩为2(我们构建我们的C++ COM库,然后构建我们的C#库).

一个问题 - 虽然这更容易,但速度很慢.我一直在浏览MSBuild的诊断输出,似乎我设置它的方式是强制每次重建依赖项.如果我已经设置了Targets="Rebuild"我会期待这个,但我认为只有在项目过期(或者文件设置为)时Targets="Build"才会构建:

<CopyToOutputDirectory>Always</CopyToOutputDirectory> 
Run Code Online (Sandbox Code Playgroud)

在项目文件中).我在诊断输出中找不到任何消息来解释为什么MSBuild目标正在重建这些依赖项,即使尚未触及依赖项.

为什么MSBuild会完全重建尚未通过上述任务更改的依赖项目?

编辑 - 更多信息

我看到以下内容:

Target "IncrementalClean: (TargetId:324)" in file "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets" from project "c:\Source\MyProject\MyDependencyProject\MyDependencyProject\MyDependencyProject.csproj" (target "CoreBuild" depends on it):
Run Code Online (Sandbox Code Playgroud)