msbuild: override symbols already definded in csproj file

This could also be used to override “TRACE” symbol from command line of msbuild.

Here is the scenario you may find it helpful:
1. keep TRACE defined when you build it from visual studio
2. turn off TRACE when you want to make an official build – from command line batch of msbuild

msbuild /p:Configuration=Release /p:DefineConstants="RANDOM-SYMBOL-HERE"

Here I used RANDOM-SYMBOL-HERE, because from what I have seen, if you have something defined here, msbuild will ignore all the symbols already defined in csproj. But if you don’t have anything here, it will keep everything already defined. But if you already have some real symbols defined, you can just use it, will never be an issue. But keep in mind: it’s a keep all or override all deal.

Be cautious, you will won’t get what you want if you simply do this: (no matter what the msdn doc says, it’s pretty misleading, took me quite some time to figure out)

msbuild /p:DefineTrace=false

Reference:

Common MSBuild Project Properties
Override conditional compilation symbols
msbuild, defining Conditional Compilation Symbols
 

Leave a Reply