开发者

How to build a PropertyGroup entry from an ItemGroup in MSBuild?

I'm very new to MSBuild and am having trouble figuring out how to construct a PropertyGroup entry from conditional parts.

Here's what I have, which is not working:

<ItemGroup>
    <CompilerDirective Include="DEBUG_PARANOID" Condition=" '$(SomeFlag)' == 'true' "/>
    <CompilerDirective Include="DEBUG"/>
    开发者_高级运维<CompilerDirective Include="TRACE"/>
</ItemGroup>

<PropertyGroup>
    ...
    <DefineConstants>@(CompilerDirective)</DefineConstants>
    ...
</PropertyGroup>

I'd like the constants that get defined to show up as DEBUG_PARANOID;DEBUG;TRACE if SomeFlag is set true, leaving out DEBUG_PARANOID if not. This is for a .csproj, by the way.

If I print out @(CompilerDirective) with a message task, it works.

My question is how to make this work inside of a PropertyGroup entry?


What you have above works. I ran this:

<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>

and got the proper output DEBUG;TRACE or DEBUG_PARANOID;DEBUG;TRACE depending on the value of the property. In what manner does this not work for you?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜