Search code examples
c#msbuildc-preprocessor

Define a preprocessor value from command line using MSBuild


I need to create a demo version of an existing large application consisting of multiple projects. I'd like to use the existing projects, and just neuter the functionality via preprocessor directives

#if DEMO
    mycode.NeuterNow();
#endif

We are building our app using MSBuild, and I'd ideally use something along the lines of:

MSBuild -DefineProperty:DEMO MySolution.sln

Does such functionality exist?


Solution

  • That's a duplicate of this one, and yes, /p:DefineConstants does work fine, and configurator is right, this will override ALL conditional symbols already defined in the Project File (which is good IMHO), so you'll have to define them all.