Jozef Izso
Jozef Izso

Reputation: 1804

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="OutputAssemblies" /> 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>

Upvotes: 2

Views: 2942

Answers (1)

Brian Kretzler
Brian Kretzler

Reputation: 9938

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

Upvotes: 7

Related Questions