So, both this and this are pretty clear. Simply pass /p:DefineConstants=\"SYMBOL\"
It doesn\'t work at all for me, even in a test project. I\'m expectin
Using DefineConstants
definitely does work. Which means you are doing something wrong. My guess is you first built the project without defining anything, then built it again. MSBuild will then see the project was built already and won't build again, but just copy output files. You should post the output of msbuild so we can be sure, but for reference I compiled your project using the necessary switches only and here is the result (full msbuild output omitted):
> msbuild ConsoleApplication1.sln /p:DefineConstants="DEV" /t:Rebuild
....
Building solution configuration "Debug|x86".
Project ... is building ConsoleApplication1.csproj" (Rebuild target(s)).
...
> ConsoleApplication1\bin\Debug\DefineConstants.exe
DEV
> msbuild ConsoleApplication1.sln /p:DefineConstants="UAT" /t:Rebuild
...
> ConsoleApplication1\bin\Debug\DefineConstants.exe
UAT
> msbuild ConsoleApplication1.sln /t:Rebuild
...
> ConsoleApplication1\bin\Debug\DefineConstants.exe
No environment provided
It seems you are not passing conditional compilation symbol. That's why you are getting output as : No environment provided. 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.
Note: if you want pass any symbol than as per your code it will print : No environment selected.