I am stuck in a situation where I have an MSBuild script that needs to read the conditional compilation symbols set in project's build property. I have the following code in my MSBuild script file
<PropertyGroup>
<DefineConstants>$(DefineConstants);INTER</DefineConstants>
</PropertyGroup>
<Target Name="Compile">
<Message Text="$(DefineConstants)"/>
<MSBuild Projects="CustomAssemblyInfo.csproj" Targets="Rebuild" Properties="DefineConstants=$(DefineConstants)" />
</Target>
I was assuming that the $(DefineConstants); will contain the value of conditional compilation symbols that are set and I can just append anything after those values like in this case INTER but somehow the values set in the project properties are not getting passed here. Can anyone please help in what am I missing?
Properties passed via Properties
property of MSBuild
task are what's called global properties, same as those passed with /p:
on command line. They take priority over any other property or environment variable even those defined unconditionally, i.e. the DefineConstants
in your .csproj
.
By passing your own DefineConstants
first you prevent it being set later from the .csproj
, so to prevent it add something like $(Constants)
in your project properties window which would redefine DefineConstants
as <DefineConstants>TRACE;DEBUG;$(Constants)</DefineConstants>
and pass Constants
from your MSBuild/NAnt script instead.
Edit: As per @sǝɯɐſ comment below
https://i.imgur.com/jZiVy7J.png
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