Search code examples
c#visual-studio-2010msbuildc-preprocessorconditional-compilation

DefineConstants works through CLI but not through VS2010 interface CL arguments


I have a simple program to look for pre-compiler constants:

#if TEST1
    MessageBox.Show("TEST1");
#endif

Now if I build the following through the CLI, things are as expected. The messagebox shows "TEST1".

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild" "C:\tests\TestBuildConstants\TestBuildConstants.sln" /p:OutDir="C:\tests\TestBuildConstants" /p:DefineConstants="TEST1" /t:Rebuild

However, if I go to Project properties -> Debug -> Command line arguments, and enter this: /p:DefineConstants="TEST1" /t:Rebuild, it refuses to pass through the constant once I run the program.

The reason I want to go through the VS GUI like this is because I want to quickly be able to test and switch between various builds as I'm coding.

What have I missed?


Solution

  • The Project properties > Debug > Command line arguments are for the parameters to pass to application after it has been built when it is run by VS. They are not arguments for MSBuild. You need to go to the Project properties > Build page and change "Conditional compilation symbols" to include TEST1.