如何从MSBuild中的ItemGroup构建PropertyGroup条目?

sco*_*obi 4 msbuild

我是MSBuild的新手,我很难搞清楚如何从条件部分构造一个PropertyGroup条目.

这是我拥有的,不起作用的:

<ItemGroup>
    <CompilerDirective Include="DEBUG_PARANOID" Condition=" '$(SomeFlag)' == 'true' "/>
    <CompilerDirective Include="DEBUG"/>
    <CompilerDirective Include="TRACE"/>
</ItemGroup>

<PropertyGroup>
    ...
    <DefineConstants>@(CompilerDirective)</DefineConstants>
    ...
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

我希望定义的常量显示为DEBUG_PARANOID; DEBUG; TRACE如果SomeFlag设置为true,如果没有则省略DEBUG_PARANOID.顺便说一句,这是针对.csproj的.

如果我用消息任务打印出@(CompilerDirective),它就可以了.

我的问题是如何在PropertyGroup条目中进行此工作?

Bri*_*ler 7

你上面有什么作品.我跑了这个:

<Target Name="Test">
  <ItemGroup>
      <CompilerDirective Include="DEBUG_PARANOID"
        Condition=" '$(SomeFlag)' == 'true' "/>
      <CompilerDirective Include="DEBUG"/>
      <CompilerDirective Include="TRACE"/>
  </ItemGroup>
  <PropertyGroup>
    <DefineConstants>@(CompilerDirective)</DefineConstants>
  </PropertyGroup>
  <Message Text="$(DefineConstants)" />
</Target>
Run Code Online (Sandbox Code Playgroud)

并获得正确的输出DEBUG; TRACE或DEBUG_PARANOID; DEBUG; TRACE取决于属性的值.这对你不起作用的方式是什么?