2011-09-01 43 views
7

Tôi muốn cấu hình và tinh chỉnh xây dựng của chúng tôi hy vọng sẽ tiết kiệm vài giây ở đây và ở đó. Tôi đã có thể tạo ra một nhiệm vụ mà xuất phát từ ResolveAssemblyReferences và sử dụng nó thay vào đó, nhưng tôi đang gặp vấn đề trong việc tìm hiểu những điều sau đây (từ Microsoft.Common.targets):ResolveProjectReferences hoạt động như thế nào?

<!-- 
    ============================================================ 
             ResolveProjectReferences 

    Build referenced projects: 

     [IN] 
     @(NonVCProjectReference) - The list of non-VC project references. 

     [OUT] 
     @(_ResolvedProjectReferencePaths) - Paths to referenced projects. 
    ============================================================ 
    --> 
    <Target 
     Name="ResolveProjectReferences" 
     DependsOnTargets="SplitProjectReferencesByType;_SplitProjectReferencesByFileExistence"> 

     <!-- 
     When building this project from the IDE or when building a .SLN from the command-line, 
     just gather the referenced build outputs. The code that builds the .SLN will already have 
     built the project, so there's no need to do it again here. 

     The ContinueOnError setting is here so that, during project load, as 
     much information as possible will be passed to the compilers. 
     --> 
     <MSBuild 
      Projects="@(_MSBuildProjectReferenceExistent)" 
      Targets="GetTargetPath" 
      BuildInParallel="$(BuildInParallel)" 
      UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" 
      Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)" 
      Condition="'@(NonVCProjectReference)'!='' and ('$(BuildingSolutionFile)' == 'true' or '$(BuildingInsideVisualStudio)' == 'true' or '$(BuildProjectReferences)' != 'true') and '@(_MSBuildProjectReferenceExistent)' != ''" 
      ContinueOnError="!$(BuildingProject)"> 

      <Output TaskParameter="TargetOutputs" ItemName="_ResolvedProjectReferencePaths"/> 
     </MSBuild> 

     <!-- 
     Build referenced projects when building from the command line. 

     The $(ProjectReferenceBuildTargets) will normally be blank so that the project's default 
     target is used during a P2P reference. However if a custom build process requires that 
     the referenced project has a different target to build it can be specified. 
     --> 
     <MSBuild 
      Projects="@(_MSBuildProjectReferenceExistent)" 
      Targets="$(ProjectReferenceBuildTargets)" 
      BuildInParallel="$(BuildInParallel)" 
      UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" 
      Condition="'@(NonVCProjectReference)'!='' and '$(BuildingInsideVisualStudio)' != 'true' and '$(BuildingSolutionFile)' != 'true' and '$(BuildProjectReferences)' == 'true' and '@(_MSBuildProjectReferenceExistent)' != ''"> 
      <Output TaskParameter="TargetOutputs" ItemName="_ResolvedProjectReferencePaths"/> 

     </MSBuild> 

     <!-- 
     Get manifest items from the (non-exe) built project references (to feed them into ResolveNativeReference). 
     --> 
     <MSBuild 
      Projects="@(_MSBuildProjectReferenceExistent)" 
      Targets="GetNativeManifest" 
      BuildInParallel="$(BuildInParallel)" 
      UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" 
      Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)" 
      Condition="'@(NonVCProjectReference)'!='' and '$(BuildingProject)'=='true' and '@(_MSBuildProjectReferenceExistent)'!=''"> 

      <Output TaskParameter="TargetOutputs" ItemName="NativeReference"/> 

     </MSBuild> 


     <!-- Issue a warning for each non-existent project. --> 
     <Warning 
      Text="The referenced project '%(_MSBuildProjectReferenceNonexistent.Identity)' does not exist." 
      Condition="'@(NonVCProjectReference)'!='' and '@(_MSBuildProjectReferenceNonexistent)'!=''"/> 
    </Target> 

Một số thông số được thông qua và một số được trả về nhưng công việc thực tế xảy ra ở đâu? Không có nhiều trên msdn - Tôi đã tìm thấy Microsoft.Build.Tasks.ResolveProjectBase, nhưng nó không được sử dụng nhiều.

Trả lời

12

ResolveProjectReferences (ít nhất là đối tượng bạn trỏ đến) là mục tiêu được sử dụng để giải quyết tham chiếu liên dự án bằng cách tạo chúng bằng cách sử dụng tác vụ <MSBuild>. Nhiệm vụ này lấy một tệp dự án để xây dựng, cũng như tên của một hoặc nhiều mục tiêu trong dự án cần được gọi như một phần của bản dựng (nó cũng có các tham số khác, nhưng bây giờ bạn có thể bỏ qua các tham số đó).

Hãy xem xét các mục tiêu sau đây:

<Target 
    Name="Build" 
    Returns="@(BuildOutput)"> 

    <ItemGroup> 
    <BuildOutput Include="bin\Debug\Foo.exe" /> 
    </ItemGroup> 
</Target> 

Nếu bạn tham khảo một dự án có chứa mục tiêu này, và muốn giải quyết "Foo" đầu ra mục tiêu, bạn sẽ có một > yếu tố < ProjectReference trong dự án của bạn như sau:

<ItemGroup> 
    <ProjectReference Include="..\SomeProject\SomeProject.proj"> 
    <Targets>Build</Targets> 
    </ProjectReference> 
</ItemGroup> 

Lưu ý rằng, nếu "Xây dựng" là mục tiêu mặc định cho dự án được tham chiếu, bạn có thể tắt hoàn toàn siêu dữ liệu "Mục tiêu". Bạn cũng có thể chỉ định nhiều mục tiêu trong siêu dữ liệu Mục tiêu (danh sách được phân cách bằng dấu chấm phẩy).

Vì vậy, mục tiêu ResolveProjectReferences của bạn sẽ đến và gọi nhiệm vụ <MSBuild>, chuyển nó ".. \ SomeProject \ SomeProject.proj" và yêu cầu nó xây dựng mục tiêu "Xây dựng". Bây giờ, vì mục tiêu "Build" xác định đầu ra thông qua thuộc tính Returns của nó (nhưng thuộc tính Outputs sẽ được sử dụng nếu thuộc tính Returns không được chỉ định), các kết quả đầu ra này sẽ được thu thập trong quá trình xây dựng và trả về tham số TargetOutputs của 01BMSBuild > . Chúng có thêm một số siêu dữ liệu bổ sung cho phép bạn tách riêng chúng bằng mục tiêu gốc. Chúng bao gồm:

  • MSBuildSourceProjectFile - dự án tham chiếu mà xây dựng tạo ra sản lượng
  • MSBuildSourceTargetName - tên của mục tiêu mà xây dựng tạo ra sản lượng

Nếu bạn đang làm việc bên trong một dự án C#, có một loạt các độ phân giải tham chiếu khác (bao gồm độ phân giải lắp ráp). Thả tôi một dòng nếu bạn muốn biết về những điều này.

+0

Vì vậy, nếu nó chỉ ra rằng giai đoạn ResolveProjectReferences đang dành một lượng đáng kể thời gian trong quá trình xây dựng, đó là hiệu quả bởi vì dự án bị chặn, chờ đợi hoặc phụ thuộc được xây dựng? Tôi đã không thể tìm thấy bất kỳ tài liệu rõ ràng về điều này. Nó không rõ ràng nếu đây là thời gian để xác định và định vị phụ thuộc (công việc thực tế), hoặc thời gian chờ đợi phụ thuộc để có sẵn (thời gian nhàn rỗi hiệu quả) – jalf

+0

Đặt cược tốt nhất của bạn là xây dựng ở mức độ Verbosity Chẩn đoán. Điều đó sẽ cho bạn thấy chính xác những gì mỗi mục tiêu đang làm (bao gồm các bản dựng lồng nhau) cũng như thời gian cho nhiều hoạt động. – tintoy

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