我不知道ItemGroup是否是正确的类型。我将得到4个不同的布尔值,这将是真或假,这取决于选择。
我想用这个“字符串”填充一个ItemGroup,这取决于真或假。这是可能的吗?或者我应该使用什么?
示例
Anders = true
Peter = false
Michael = false
Gustaf = true我的ItemGroup应该有Anders和Gustaf。
这是可能的吗?或者我应该如何解决它?
发布于 2012-10-22 21:08:29
既然你有一大堆项目,最好从一开始就将它们存储在ItemGroup中,因为毕竟这就是它的目的,而且它还允许转换等。例如,这可以实现你想要的:
<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>然而,如果它们必须是属性,我认为除了像这样手动枚举它们之外,没有其他方法:
<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>https://stackoverflow.com/questions/13010851
复制相似问题