在随后的ItemDefinitionGroup
中,您可以创建当前元数据的副本,然后对其调用Replace:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Dump" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<SomeItem>
<SomeMetaData>foo,bar,baz</SomeMetaData>
</SomeItem>
</ItemDefinitionGroup>
<ItemGroup>
<SomeItem Include="one;two" />
</ItemGroup>
<ItemDefinitionGroup>
<SomeItem>
<!-- Remove "bar" -->
<SomeMetaData>$([System.String]::Copy('%(SomeMetaData)').Replace('bar',''))</SomeMetaData>
</SomeItem>
</ItemDefinitionGroup>
<Target Name="Dump">
<Message Text="SomeItem.SomeMetaData: @(SomeItem -> '%(Identity)=%(SomeMetaData)') " />
</Target>
</Project>
下面是使用 MSBuild 14 运行时的输出:
> MSBuild .\foo.proj
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2/17/2017 7:09:48 PM.
Project "D:\temp\mb\foo.proj" on node 1 (default targets).
Dump:
SomeItem.SomeMetaData: one=foo,,baz;two=foo,,baz
Done Building Project "D:\temp\mb\foo.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.03