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

爱⌒轻易说出口 提交于 2019-12-22 09:18:25

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/5345865/how-to-build-a-propertygroup-entry-from-an-itemgroup-in-msbuild

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!