在msbuild中复制项目的元数据

问题描述:

我正在基于项目A创建项目B,并希望将A的所有元数据复制到B(并添加一些其他元数据).

I am creating Item B based on item A, and would like to copy all of A's metadata to B (and add some additional meta data).

<ItemGroup>
  <B Include="@A">
    <M1>%(A.M1)</M1>
    <M2>%(A.M2)</M2>
    <M3>%(A.M3)</M3>
    ...
    <M100>%(A.M100)</M100>
    ... Additional metadata specific to B ...
  </B>
</ItemGroup>

不是将每个元数据M1-M100从A单独复制到B,而是可以告诉msbuild将所有元数据从A复制到B? 这样的批处理元数据副本"可以设置条件吗?

Instead of copying each metadata M1 - M100 individually from A to B, is it possible to tell msbuild to copy all metadata from A to B?
Could such a "batch metadata copy" be conditioned?

类似的东西:

<ItemGroup>
  <B Include="@A">        
    ... Additional metadata specific to B ...
  </B>
</ItemGroup>
<CopyMetadata From="@A" To="@B" Condition="... Check something ..."/>

谢谢.

复制项目时,其

When you copy items, its metadata is copied too. See the working example for MSBuild v4.0:

<Project DefaultTargets="DoSomethingWithB" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <A Include="1">
      <M1>M1 (1)</M1>
      <M2>M2 (1)</M2>
      <M3>M3 (1)</M3>
      <N4>HERE</N4>
    </A>
    <A Include="2">
      <M1>M1 (2)</M1>
      <M2>M2 (2)</M2>
      <M3>M3 (2)</M3>
    </A>
  </ItemGroup>

  <Target Name="PrepareB" Outputs="%(A.Identity)">
     <ItemGroup>
       <B Include="@(A)">
         <M4>M4 (%(A.Identity))</M4>
         <M5 Condition="'%(A.N4)'!=''">M5 (%(A.Identity) for A.N4 != '')</M5>
       </B>
     </ItemGroup>      
  </Target>

  <Target Name="DoSomethingWithB"
          DependsOnTargets="PrepareB">

     <Message Text="ItemGroup A" />
     <Message Text="%(A.Identity): M1=%(A.M1), M2=%(A.M2), M3=%(A.M3), N4=%(A.N4)" />

     <Message Text="ItemGroup B" />
     <Message Text="%(B.Identity): M1=%(B.M1), M2=%(B.M2), M3=%(B.M3), N4=%(B.N4), M4=%    (B.M4), M5=%(B.M5)" />
  </Target>
</Project>

输出:

ItemGroup A
1:M1 = M1(1),M2 = M2(1),M3 = M3(1),N4 = HERE
2:M1 = M1(2),M2 = M2(2),M3 = M3(2),N4 =
项目组B
1:M1 = M1(1),M2 = M2(1),M3 = M3(1),N4 = HERE,M4 = M4(1),M5 = M5(1对于A.N4!='')
2:M1 = M1(2),M2 = M2(2),M3 = M3(2),N4 =,M4 = M4(2),M5 =

ItemGroup A
1: M1=M1 (1), M2=M2 (1), M3=M3 (1), N4=HERE
2: M1=M1 (2), M2=M2 (2), M3=M3 (2), N4=
ItemGroup B
1: M1=M1 (1), M2=M2 (1), M3=M3 (1), N4=HERE, M4=M4 (1), M5=M5 (1 for A.N4 != '')
2: M1=M1 (2), M2=M2 (2), M3=M3 (2), N4=, M4=M4 (2), M5=