8

あちこちで数秒節約できることを期待して、ビルドのプロファイルと調整を行いたいと思います。ResolveAssemblyReferencesから派生したタスクを作成して代わりに使用することはできましたが、次のことを理解するのに問題があります(Microsoft.Common.targetsから)。

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

一部のパラメーターが渡され、一部が返されますが、実際の作業はどこで行われますか?msdnにはあまりありません-Microsoft.Build.Tasks.ResolveProjectBaseを見つけましたが、あまり役に立ちません。

4

1 に答える 1

14

ResolveProjectReferences(少なくともあなたが指しているもの)は、<MSBuild>タスクを使用してそれらを構築することによってプロジェクト間参照を解決するために使用されるターゲットです。このタスクでは、ビルドするプロジェクトファイルと、ビルドの一部として呼び出す必要のあるプロジェクト内の1つ以上のターゲットの名前を取得します(他のパラメーターも使用しますが、現時点では無視できます)。

次のターゲットを検討してください。

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

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

このターゲットを含むプロジェクトを参照し、「Foo」ターゲットの出力を解決したい場合は、次のようにプロジェクトに<ProjectReference>要素があります。

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

「ビルド」が参照されるプロジェクトのデフォルトのターゲットである場合、「ターゲット」メタデータを完全にオフのままにしておくことができることに注意してください。Targetsメタデータ(セミコロンで区切られたリスト)で複数のターゲットを指定することもできます。

したがって、ResolveProjectReferencesターゲットがやって来て、<MSBuild>タスクを呼び出し、「.. \ SomeProject \ SomeProject.proj」を渡して、「Build」ターゲットをビルドするように要求します。これで、「ビルド」ターゲットはそのReturns属性を介して出力を指定するため(ただし、Returns属性が指定されていない場合は、Outputs属性が使用されます)、これらの出力はビルド中に収集され、<MSBuild>タスクのTargetOutputsパラメーターで返されます。 。それらには、メタデータのいくつかの追加部分が追加されており、ターゲットを発信することによってそれらを分離することができます。これらには以下が含まれます:

  • MSBuildSourceProjectFile-ビルドが出力を生成した参照プロジェクト
  • MSBuildSourceTargetName-ビルドが出力を生成したターゲットの名前

C#プロジェクト内で作業している場合は、参照解決(アセンブリ解決を含む)の他の段階がたくさんあります。これらについて知りたい場合は、私に連絡してください。

于 2011-09-01T13:28:21.347 に答える