Replies: 3 comments 5 replies
-
According to Item element (MSBuild), the Update attribute is not valid in an Item in an ItemGroup in a Target. I wish MSBuild warned about that. So, if you need to do this in a Target and cannot use Update, I think a custom task (inline or otherwise) will be the easiest solution. |
Beta Was this translation helpful? Give feedback.
-
For batching, this seems to work: <?xml version="1.0" encoding="utf-8"?>
<!-- https://github.com/dotnet/msbuild/discussions/7753 -->
<Project>
<Target Name="Default">
<ItemGroup>
<A Include="Blue" Meta0="Carrot" Meta1="Happy" Meta2="Pitch" />
<A Include="Red" Meta0="Bilberry" Meta1="Anxious" Meta2="Yaw" />
<A Include="Cyan" Meta0="Rhubarb" Meta1="Tired" Meta2="Roll" />
</ItemGroup>
<ItemGroup>
<B Include="Garlic" Meta0="Blue" Meta1="Curious" Meta2="Desk" />
<B Include="Cucumber" Meta0="Red" Meta1="Flabbergasted" Meta2="Chair" />
<B Include="Olive" Meta0="Purple" Meta1="Clever" Meta2="Bookshelf" />
</ItemGroup>
<ItemGroup>
<_SwapB Include="%(B.Meta0)">
<Meta0>%(Identity)</Meta0>
<Meta1>%(Meta1)%(Meta2)</Meta1>
</_SwapB>
<_ModifiedA Include="@(A)" Condition="%(Identity) != '' and '@(_SwapB)' != ''">
<Meta0>@(_SwapB->'%(Meta0)')</Meta0>
<Meta1>@(_SwapB->'%(Meta1)')</Meta1>
</_ModifiedA>
<A Remove="@(_ModifiedA)" />
<A Include="@(_ModifiedA)" />
</ItemGroup>
<Message Importance="high" Text="A: Identity=%(A.Identity) Meta0=%(A.Meta0) Meta1=%(A.Meta1) Meta2=%(A.Meta2)" />
</Target>
</Project> Output:
|
Beta Was this translation helpful? Give feedback.
-
Here's another (simpler) variant of the solution proposed by @KalleOlaviNiemitalo <ItemGroup>
<_SwapB Include="@(B->'%(Meta0)')">
<Meta0>%(B.Identity)</Meta0>
<Meta1>%(B.Meta1)%(B.Meta2)</Meta1>
<Meta2/> <!-- this not needed it seems but I don't know why! -->
</_SwapB>
<A Condition="'%(Identity)' != '' AND '@(A)' != '' AND '@(_SwapB)' != ''">
<Meta0>@(_SwapB->'%(Meta0)')</Meta0>
<Meta1>@(_SwapB->'%(Meta1)')</Meta1>
</A>
<_SwapB Remove="@(_SwapB)"/>
</ItemGroup> This is almost the same except we don't need to Modify But a request to MSBuild team... @Forgind @rainersigwald |
Beta Was this translation helpful? Give feedback.
-
The more elaborate question would be...
How do I update one item with the other item's metadata when their identities are different and somehow I need to compare different metadata for equality?
For all the
B.Meta0
items present inA
items, updateA.Meta0
withB
's Identity andA.Meta1
withB.Meta{1,2}
Beta Was this translation helpful? Give feedback.
All reactions