Create macro for custom configuration same as DEBUG macro for debug configuration

1.2k Views Asked by At

in a wcf C# application, I am using:

#if DEBUG
    //debug mode
#else 
    //release mode
#endif

to detect if I am in debug mode or release mode and have different logic for each.

But now I have created a new Configuration in the configuration manager called "Local"

how can I also create a macro similar to "DEBUG" for when I'm building in "Local" configuration. So that I can do something like

#if DEBUG
    //debug mode
#elif LOCAL
    //local mode
#else
    //release mode
#endif
2

There are 2 best solutions below

0
On BEST ANSWER
  1. Create a "Local" configuration. Open menu "Build" and select "Configuration Manager...". Open the "Active Solution Configuration" drop down and select "New". Create a configuration named "Local" and copy settings from "Debug". Keep "Create new project configurations" on.

  2. Change your projects to define. Select your new "Local" configuration in the drop down besides the Start button in the toolbar. Open the project configuration for each of your projects and select the category "Build". Make sure that Configuration is set to "Active (Local)" or "Local". In "Conditional compilation symbols" add "LOCAL". Repeat this for all your projects:

    Project build configuration

  3. Use it. Add conditional compilation blocks as shown in your question.

0
On

You can define additional constants in project config in "Conditional compilation symbols" under "Build" tab. You should add LOCAL in that case. You can also use #define inside source files.