Return the ReferenceCopyLocalPaths from <MSBuild> task

喜你入骨 提交于 2019-12-08 08:56:15

问题


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>

回答1:


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



来源:https://stackoverflow.com/questions/6161824/return-the-referencecopylocalpaths-from-msbuild-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!