如何为ItemGroup
中的每个项展开列表属性?如果我尝试了以下内容,则会针对所有项目扩展属性:
<ItemGroup>
<Foo Include="foo">
<Bar>a;b;c</Bar>
</Foo>
<Foo Include="bar">
<Bar>d;e;f</Bar>
</Foo>
</ItemGroup>
<Target Name="Build">
<ItemGroup>
<Foobars Include="%(Foo.Bar)" />
</ItemGroup>
<Message Text="%(Foo.Identity) %(Foo.Bar) @(Foobars -> '%(Identity)', ' ')" />
</Target>
输出结果为:
foo a;b;c a b c d e f
bar d;e;f a b c d e f
我需要的是:
foo a;b;c a b c
bar d;e;f d e f
答案 0 :(得分:1)
如果您将原始%(Foo.Identity)
和%(Foo.Bar)
作为元数据添加到Foobars
项,则可以限制迭代元数据值时@(Foobars)
包含的值:
<Project>
<ItemGroup>
<Foo Include="foo">
<Bar>a;b;c</Bar>
</Foo>
<Foo Include="bar">
<Bar>d;e;f</Bar>
</Foo>
</ItemGroup>
<Target Name="Build">
<ItemGroup>
<Foobars Include="%(Foo.Bar)">
<Foo>%(Foo.Identity)</Foo>
<Bar>%(Foo.Bar)</Bar>
</Foobars>
</ItemGroup>
<Message Text="%(Foobars.Foo) %(Foobars.Bar) @(Foobars -> '%(Identity)', ' ')" Importance="high" />
</Target>
</Project>
产生
$ dotnet msbuild
Microsoft (R) Build Engine version 15.3.234.47922 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
foo a;b;c a b c
bar d;e;f d e f