How to create a PropertyGroup record from ItemGroup in MSBuild?

I am very new to MSBuild, and it’s hard for me to figure out how to build a PropertyGroup record from conditional parts.

Here is what I have that doesn't work:

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

I would like the constants that were defined as DEBUG_PARANOID, DEBUG; TRACE if SomeFlag is set to true, leaving DEBUG_PARANOID if not. This is for .csproj, by the way.

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

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

+4
source share
1 answer

What you have on the work. 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 received the correct output DEBUG, TRACE or DEBUG_PARANOID; DEBUG; TRACE depending on the value of the property. How does this not work for you?

+7
source

Source: https://habr.com/ru/post/1344200/


All Articles