Add output or transfer data from child to parent p

2019-08-24 06:43发布

问题:

I use msbuild in main.proj to build a project like this:

 <MSBuild Projects="outs.proj" Targets="Build">
     <Output ItemName="CustomOutputs" TaskParameter="TargetOutputs"/>
</MSBuild>

Inside outs.proj I have a custom Target, I need to add an output from this target to get .dll,.pdb,..., and .mycustomfiles

How can I send data from child project to parent project ?

Thanks in advance for your help.

回答1:

I'd recommend you simply Import the dependant project, however the basic scenario you described can be achieved with Target's Outputs or Returns and corresponding Output's TargetOutputs although there are few caveats as it's designed for incremental builds and not as a data transfer object.

foo.build

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Foo1">
    <MSBuild Projects="bar.build">
      <Output TaskParameter="TargetOutputs" ItemName="Bar" />
    </MSBuild>
    <Message Text="%(Bar.Identity)" />
  </Target>

  <Import Project="bar.build" />
  <Target Name="Foo2" DependsOnTargets="Bar">
    <Message Text="%(Bar.Identity)" />
  </Target>
</Project>

bar.build

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Bar" Outputs="@(Bar)">
    <ItemGroup>
      <Bar Include="**\*.dll" />
    </ItemGroup>
  </Target>
</Project>