msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

WithMetadataValue does not accept batching argument

Open iskiselev opened this issue 3 years ago • 1 comments

Issue Description

WithMetadataValue item function does not return anything when parameter is from batch

Steps to Reproduce

<Project>
  <ItemGroup>
    <ItemA Include="1.txt" M="a" />
    <ItemA Include="2.txt" M="b" />
    <ItemA Include="3.txt" M="c" />
    <ItemB Include="a.txt" />
    <ItemB Include="c.txt" />
  </ItemGroup>
  

  <Target Name="Build" >
    <Warning Text="* @(ItemA->WithMetadataValue('M','%(Filename)'))" Condition="'%(ItemB.Filename)' != ''"/>
  </Target>
</Project>

Expected Behavior

Two warnings with matching ItemA in each:

warning : * 1.txt
warning : * 3.txt

Actual Behavior

Two empty warnings:

warning : *
warning : *

Analysis

In most case there is a way to workaround the issue using few temporary ItemGroups and different way of batching.

iskiselev avatar Jun 04 '22 02:06 iskiselev

I poked around with this a bit and it looks like you can't get ItemB's filename from within the call of WithMetadataValue like you're expecting here. I suspect this is directly related to the fact that an item function is being called at the same time that metadata from a different item is being used. Not 100% sure what's happening here. @rainersigwald might have an idea

https://docs.microsoft.com/visualstudio/msbuild/item-metadata-in-task-batching https://docs.microsoft.com/visualstudio/msbuild/item-functions

benvillalobos avatar Jun 09 '22 17:06 benvillalobos