我的团队有一个大型解决方案(约 500 个 csproj)。我们使用 VS2012,并使用 TFS Build 进行构建,TFS Build 使用 MSBuild 4。目前我们串行构建,但我们希望并行构建(使用msbuild /maxcpucount:4
)。然而,当我在我的 4-proc 机器上尝试它时,我遇到了一个奇怪的失败:
11:2>CSC : fatal error CS0042: Unexpected error creating debug information file 'C:\Common\obj\Debug\Common.PDB' -- 'C:\Common\obj\Debug\Common.pdb: The process cannot access the file because it is being used by another process. [C:\Common\Common.csproj]
查看日志,2 个 msbuild 节点正在尝试构建相同的 csproj,因此在写入一些输出时发生冲突:
10>Project "C:\Utils\Utils.csproj" (10) is building "C:\Common\Common.csproj" (11) on node 4 (default targets).
46:2>Project "C:\Objects\Objects.csproj" (46:2) is building "C:\Common\Common.csproj" (11:2) on node 1 (default targets).
为什么 MSBuild 会尝试构建同一个项目两次?
Cause:有人打电话来<MSBuild Projects="Common.csproj" Properties="..." />
。然后,MSBuild 认为它应该使用这些不同的属性再次构建 Common.csproj,并且它恰好与 Common.csproj 的常规编译同时发生。
Fix: Call <MSBuild ... />
没有那些不需要的属性。
Test:
共同目标
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Importance="high" Text="Build in $(MSBuildThisFile)" />
</Target>
<Target Name="After" DependsOnTargets="Build">
<Message Importance="high" Text="After in $(MSBuildThisFile)" />
</Target>
</Project>
其他目标
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Importance="high" Text="Build in $(MSBuildThisFile)" />
<MSBuild Projects="common.targets" Targets="Build" /> <!-- regular builds -->
<MSBuild Projects="common.targets" <!-- custom invocation with properties -->
Targets="After"
Properties="myprop=myvalue"
/>
</Target>
</Project>
Run:
> msbuild other.targets /clp:verbosity=minimal
Build in other.targets
Build in common.targets
Build in common.targets <<<< Common.targets Build is invoked again
After in common.targets
事实上,删除Properties="myprop=myvalue"
解决了这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)