9

我不知道是否ItemGroup是正确的类型。我会得到 4 个不同的布尔值,根据选择是真还是假。

我想ItemGroup根据真假填充这个“字符串”。这是可能的还是我应该使用什么?

例子

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

ItemGroup应该有安德斯和古斯塔夫。

这是可能的还是我应该如何解决这个问题?

4

1 回答 1

13

由于您有一堆项目,最好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>
于 2012-10-22T13:08:29.367 回答