开发者

Return the ReferenceCopyLocalPaths from <MSBuild> task

I have custom MSBuild project file with few <ProjectReferences>. I'm calling the <MSBuild Projects="@(ProjectReference)" Targets="Build"> task and I can get all the built assemblies using the <Output TaskParameter="TargetOutputs" ItemName="OutputAssemb开发者_开发百科lies" /> element and I'm copying @(OutputAssemblies) to destination directory.

I want to able to get the @(ReferenceCopyLocalPaths) item property from the ResolveAssemblyReferences target but I can't figure out how to output this property.

<Target Name="BuildDocumentationForReferencedProjects">
  <MSBuild
    Projects="@(ProjectReference)"
    Targets="Build"
    BuildInParallel="true"
    Properties="DocumentationFile=$(DllDir)\%(FileName).xml"
  >
    <Output TaskParameter="TargetOutputs" ItemName="OutputAssemblies" />
  </MSBuild>

  <Copy SourceFiles="@(OutputAssemblies)" DestinationFolder="$(DllDir)" />
</Target>


Add the following custom target to your project file, or to a file imported by all projects you want to get this behavior with...

  <Target Name="MyResolveReferences"
    DependsOnTargets="ResolveReferences"
    Returns="@(ReferenceCopyLocalPaths)">
  </Target>

Then, you can call this target directly and capture the item array you are interested in, since this transitory target declares it as its "Returns" value,

  <Target Name="BuildDocumentationForReferencedProjects">
   <MSBuild
     Projects="@(ProjectReference)"
     Targets="MyResolveReferences"
     ...
     >
     <Output
        TaskParameter="TargetOutputs"
        ItemName="MyReferenceCopyLocalPaths"
        />
   </MSBuild>
   <Message Text="Paths = '@(MyReferenceCopyLocalPaths)'" />
  </Target>

In addition to @(ReferenceCopyLocalPaths) there are a number of other item arrays that might be interesting, just look in Microsoft.Common.targets at all the Outputs declared for the call to the ResolveAssemblyReference task in the ResolveAssemblyReferences target (mine is ~line 1400).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜