我是MSBuild的新手,在弄清楚如何从条件部分构造PropertyGroup条目时遇到了麻烦。
这是我所拥有的,不起作用:
<ItemGroup>
<CompilerDirective Include="DEBUG_PARANOID" Condition=" '$(SomeFlag)' == 'true' "/>
<CompilerDirective Include="DEBUG"/>
<CompilerDirective Include="TRACE"/>
</ItemGroup>
<PropertyGroup>
...
<DefineConstants>@(CompilerDirective)</DefineConstants>
...
</PropertyGroup>
我希望将定义的常量显示为DEBUG_PARANOID; DEBUG; TRACE(如果SomeFlag设置为true),否则不显示DEBUG_PARANOID。顺便说一下,这是用于.csproj的。
如果我通过消息任务打印出@(CompilerDirective),它将起作用。
我的问题是如何在PropertyGroup条目中进行此项工作?
最佳答案
你上面有什么工作。我跑了这个:
<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>
并得到适当的输出
调试;跟踪
要么
DEBUG_PARANOID; DEBUG; TRACE
取决于属性的值。这对您不起作用?