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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With