I don't know if ItemGroup
is the right type to use. I will get 4 different booleans that will be true or false depending on choice.
I would like to fill up an ItemGroup
with this "strings" depending on the true or false. Is that possible or what should I use?
Example
Anders = true
Peter = false
Michael = false
Gustaf = true
My ItemGroup
should then have
Anders and Gustaf.
Is that possible or how should I solve that?
Identifies the ItemGroup. Defines the inputs for the build process. There may be zero or more Item elements in an ItemGroup. Required root element of an MSBuild project file. Starting with .NET Framework 3.5, the ItemGroup element can appear inside a Target element. For more information, see Targets.
ItemGroups can have conditions applied by using the Condition attribute. In that case, the items are only added to the item list if the condition is satisfied. See MSBuild conditions The Label attribute is used in some build systems as a way to control build behaviors.
When multiple ItemGroup elements are used, items are combined into a single ItemGroup. For example, some items might be included by a separate ItemGroup element that's defined in an imported file. ItemGroups can have conditions applied by using the Condition attribute.
MSBuild conditions. MSBuild supports a specific set of conditions that can be applied wherever a Condition attribute is allowed.
Since you have a bunch of items, it would be better to store them in an ItemGroup
from the start since after all that is what it is meant for and it also allows transformations 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 must be properties, I do not think there is another way than enumerating them all manually like so:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With