Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append conditional compilation symbols in project properties with MSBuild?

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?

like image 284
Afraz Ali Avatar asked Jun 11 '14 08:06

Afraz Ali


1 Answers

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

enter image description here

like image 165
Ilya Kozhevnikov Avatar answered Oct 05 '22 18:10

Ilya Kozhevnikov