MSBuild ItemGroup with the condition

I don't know if the ItemGroup type is ItemGroup . I get 4 different booleans that will be true or false depending on the choice.

I would like to populate an ItemGroup these β€œstrings” depending on true or false. Is this possible or what should I use?

Example

 Anders = true Peter = false Michael = false Gustaf = true 

My ItemGroup must have Anders and Gustav.

Is it possible or how to solve it?

+6
source share
1 answer

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)"/> <!--AllNames contains Anders and Gustaf--> </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> 
+9
source

All Articles