msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

When chaining item functions and comparing the result to empty string, the comparison will return false incorrectly.

Open ericstj opened this issue 3 weeks ago • 0 comments

Issue Description

Given the items:

    <ItemGroup>
      <TestItem Include="Test1" Foo="Bar" />
      <TestItem Include="Test2" />
    </ItemGroup>

And the comparison:

<Message Text="Don't have Test1/@Foo=Baz" Condition="'@(TestItem->WithMetadataValue('Identity', 'Test1')->WithMetadataValue('Foo', 'Baz'))' == ''" Importance="high" />

I would expect the condition to be true, but it is false. Emitting the result of the item function does show that it is an empty string.

Steps to Reproduce

Create a project, add the following.


  <Target Name="TestItem">

    <ItemGroup>
      <TestItem Include="Test1" Foo="Bar" />
      <TestItem Include="Test2" />
    </ItemGroup>

    <Message Text="@(TestItem->WithMetadataValue('Identity', 'Test1'))" Importance="high" />
    <Message Text="Have Test1" Condition="'@(TestItem->WithMetadataValue('Identity', 'Test1'))' != ''" Importance="high" />
    <Message Text="Don't have Test3" Condition="'@(TestItem->WithMetadataValue('Identity', 'Test3'))' == ''" Importance="high" />
    <Message Text="Have Test1/@Foo=Bar" Condition="'@(TestItem->WithMetadataValue('Identity', 'Test1')->WithMetadataValue('Foo', 'Bar'))' != ''" Importance="high" />
    <Message Text="Don't have Test1/@Foo=Baz" Condition="'@(TestItem->WithMetadataValue('Identity', 'Test1')->WithMetadataValue('Foo', 'Baz'))' == ''" Importance="high" />

  </Target>

build with dotnet msbuild /t:TestItem /tl:off

Expected Behavior

Emits:

  Test1
  Have Test1
  Don't have Test3
  Have Test1/@Foo=Bar
  Don't have Test1/@Foo=Baz

Actual Behavior

Emits:

  Test1
  Have Test1
  Don't have Test3
  Have Test1/@Foo=Bar

Analysis

No response

Versions & Configurations

MSBuild version 18.0.2+b0f34d51f for .NET

ericstj avatar Dec 05 '25 02:12 ericstj