Add output or transfer data from child to parent project

坚强是说给别人听的谎言 提交于 2019-12-11 19:20:00

问题


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>


来源:https://stackoverflow.com/questions/25393763/add-output-or-transfer-data-from-child-to-parent-project

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