2013-07-01 50 views
5

我的團隊有一個很大的解決方案(〜500 csproj's)。我們使用VS2012,並使用TFS Build構建,該構建使用MSBuild 4.目前我們連續構建,但我們想要並行構建(使用msbuild /maxcpucount:4)。然而,當我試試我的4個處理器的機器上,我得到一個奇怪的故障:MSBuild/m:4失敗,因爲它構建了兩次相同的項目

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的嘗試構建同一個項目兩次?

回答

3

原因:有人打電話給<MSBuild Projects="Common.csproj" Properties="..." />。然後,MSBuild認爲它應該使用這些不同的屬性再次構建Common.csproj,並且恰巧發生在Common.csproj的常規編譯的同時。

修復:撥打<MSBuild ... />沒有這些不必要的屬性。

測試:

Common.targets

<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> 

Other.targets

<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> 

運行:

> 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"可以解決問題。