I'm possibly just blind, but is there a command line to specify conditional compilation symbols in MSBUILD?
I currently have this Line in my buildscript:
SET MSBUILD=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe SET CONFIG=Debug %MSBUILD% /p:Configuration=%CONFIG% /p:OutputPath=..\..\output source\MyProject\MyProject.csproj
And I'd like to add a condition. In Visual Studio, i can just go into Project Properties => Build => Conditional compilation symbols, but I have not seen that option for msbuild?
Bonus Karma if you know if I can completely override all symbols already specified in the .csproj files to make sure that only the conditionals from my Buildscript go in.
Right before this closing xml tag, add following xml tag, save the file in text editor and close the file. Now open the solution in Visual Studio and if you look at Project Properties > Build > General > Conditional compilation symbols, you will see MY_CONST_1, MY_CONST_2 and MY_CONST_3.
MSBuild conditional constructs. MSBuild provides a mechanism for either/or processing with the Choose, When, and Otherwise elements. Use the Choose element. The Choose element contains a series of When elements with Condition attributes that are tested in order from top to bottom until one evaluates to true.
Just go to project properties and than click on build tab (left side below application). you will find one box asking for conditional compilation symbol. Just write your constants as per your desired output. for ex. in your example, to print "DEV" write DEV at conditional compilation box and rebuild your project. i am sure it will work.
You have to define something to override all the symbols already defined: msbuild /p:DefineConstants="RANDOM-SYMBOL" Show activity on this post. What is said in the answers is valid for C# code, and also for ASP.NET "codebehind" C# code.
Have you seen this? (most info is in the penultimate post)
/p:DefineConstants="MYSYMBOL1;MYSYMBOL2"
I had to use a space instead of a semicolon a la this post by Björn Lasar: http://www.linqinpark.net/2009/01/13/MSBuildWithMultipleDefineConstants.aspx
Update: the blog has disappeared; retrieved via Internet Archive:
Recently I had to use MSBuild directly to automate some builds. I also had to configure some preprocessor defines based upon a configuration. This is usually done by an Argument like this
"/p:DefineConstants=MY_PREPROC_FLAG"
Nothing special here since there are enough comments on the web about that. Today I needed one Flag more and I used the commandline syntax similar to how I knew it from the IDE:
"/p:DefineConstants=MY_PREPROC_FLAG;YET_ANOTHER_FLAG"
but this one didn't work.
So the point is that if you want to support multiple defines to a project by commandline you'll have to separate them by simple spaces...
"/p:DefineConstants=MY_PREPROC_FLAG YET_ANOTHER_FLAG"
and it will be added to the (semicolon-separated) Defines from the IDE. Good to know I think...
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