Since you have a bunch of elements, it would be better to save them in an ItemGroup from the very beginning, since after all this is intended, it also allows conversion, etc. For example, this achieves what you want.
<ItemGroup> <Names Include="Anders"> <Value>True</Value> </Names> <Names Include="Peter"> <Value>False</Value> </Names> <Names Include="Michael"> <Value>False</Value> </Names> <Names Include="Gustaf"> <Value>True</Value> </Names> </ItemGroup> <Target Name="GetNames"> <ItemGroup> <AllNames Include="%(Names.Identity)" Condition="%(Names.Value)==true"/> </ItemGroup> <Message Text="@(AllNames)"/> </Target>
However, if they should be properties, I donβt think there is another way than listing them all manually:
<PropertyGroup> <Anders>True</Anders> <Peter>False</Peter> <Michael>False</Michael> <Gustaf>True</Gustaf> </PropertyGroup> <Target Name="GetNames"> <ItemGroup> <AllNames Include="Anders" Condition="$(Anders)==true"/> <AllNames Include="Peter" Condition="$(Peter)==true"/> <AllNames Include="Michael" Condition="$(Michael)==true"/> <AllNames Include="Gustaf" Condition="$(Gustaf)==true"/> </ItemGroup> <Message Text="@(AllNames)"/> </Target>
stijn source share