msbuild
msbuild copied to clipboard
AnyHaveMetadataValue returns non boolean value when item group is empty
Consider:
<Target Name="Foo">
<ItemGroup>
<Var Include="A" />
<Var Include="B" />
</ItemGroup>
<PropertyGroup>
<X>@(Var->AnyHaveMetadataValue('Identity', 'A'))</X>
</PropertyGroup>
<ItemGroup>
<Var Remove="@(Var)" />
</ItemGroup>
<PropertyGroup>
<Y>@(Var->AnyHaveMetadataValue('Identity', 'A'))</Y>
</PropertyGroup>
<Message Text="X=$(X) Y=$(Y)" Importance="High" />
</Target>
Result:
X=true Y=
This makes using it much less elegant, as also the documentation a bit misleading.
To change this I think we'd have to figure out why it's happening. Is it because we interpret @(Var)
, see that it's empty, and don't bother calling the item function? I suspect that's it. If so, we may not be able to change this since it's not clear whether the item functions can handle an empty-list input. But we'd need to debug in to figure out what's up.
it should be able to work in the item functions if you special case for when the lists are empty.
Yeah, I'm also hitting this in a similar fashion where I have a code like this to check for a default Program.{cs,vb,fs}
file in the project.
<_ProgramSourceFileIsPresent>@(Compile->AnyHaveMetadataValue('Identity', 'Program$(DefaultLanguageSourceExtension)'))</_ProgramSourceFileIsPresent>
Just hit something (probably) similar when trying to parse PackageVersion statements for a specific package. Is there any workaround for this?
A working workaround that is rather inelegant but works for Conditions:
@(Var->WithMetadataValue('Identity', 'A')->Count()) >= 1