2013-07-01 33 views
5

Nhóm của tôi có một giải pháp lớn (~ 500 csproj). Chúng tôi sử dụng VS2012 và xây dựng bằng TFS Build, sử dụng MSBuild 4. Hiện tại chúng tôi xây dựng serially, nhưng chúng tôi muốn xây dựng song song (sử dụng msbuild /maxcpucount:4). Tuy nhiên, khi tôi thử nó trên máy tính của 4-proc của tôi, tôi nhận được một thất bại lạ:MSBuild/m: 4 không thành công vì nó xây dựng cùng một dự án hai lần

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]

Nhìn vào các bản ghi, 2 nút msbuild đang cố gắng xây dựng cùng csproj, và do đó va chạm vào viết một số đầu ra:

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

Tại sao MSBuild sẽ cố gắng xây dựng các dự án tương tự hai lần?

Trả lời

3

Nguyên nhân: Ai đó đang gọi <MSBuild Projects="Common.csproj" Properties="..." />. Sau đó, MSBuild nghĩ rằng nó nên xây dựng Common.csproj một lần nữa với các thuộc tính khác nhau, và nó đã xảy ra cùng một lúc với việc biên dịch thường xuyên của Common.csproj.

Khắc phục: Gọi <MSBuild ... /> mà không có các thuộc tính không cần thiết đó.

Test:

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> 

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 

Và thực sự, xóa Properties="myprop=myvalue" giải quyết vấn đề.

Các vấn đề liên quan