When I select the "Debug" configuration, the DEBUG
constant is active. When I select the "Release" configuration, the DEBUG
constant is inactive.
How can I create my own configurations so that they include my own defined constants. Basically, I want it so that if I select the configuration "FOOBAR" that there is a constant FOO
and BAR
in my project active.
I'm basically trying to avoid putting in a bunch of #define FOO
in my projects, then commenting/uncommenting them out when I need/don't need them.
This is a very old question, but here's how you'd do it in VS2013.
Adding a constant in the Project Properties doesn't work for me.
What does work is to open the .csproj file for your project, find your configuration name, and add something to the "DefineConstants" section.
In this example, whenever I'm in VS2013 and I change my Configuration to "BO4_Production", the source code will immediately reflect this, and any sections will reflect this:
It's strange that this seems to be the only way to make a
#define
kick in, just by changing the configuration.A few months later...
Actually, scrap that. Even in VS2015, I can add my conditional symbol in either the "Build" tab or directly in the .csproj file, but some of the projects in my solution just get it wrong. For example, they have my symbol defined, when for that configuration, it shouldn't be defined. (I checked the Configuration Manager window, and it is all setup correctly, but VS2015 just doesn't get it right sometimes..)
According to this article you can define compilation constants in the build tab of your project properties.
EDITED: To define build configurations you can go to Build > Configuration manager and I think you can define compilation constants there too.
Below I summarized how to create a new build configuration (say TEST_BUILD) other than debug/release build and how to define a conditional compilation under a new build configuration?
Go to Build -> Configuration Manager -> select "New" -> type TEST_BUILD and select the copy settings from -> Empty -> press OK.
Alternatively you can copy either a debug or release build settings to your new TEST_BUILD apart from TEST_BUILD specific build settings.
Step 1: Copy the existing settings to your new build config:
copy setting from -> -> press OK. [or]
copy setting from -> -> press OK.
Step 2: Define a Macro:
Goto Properties -> Configuration Properties -> C/C++ -> Preprocessor ->Preprocessor Definitions -> Define/Add TEST_BUILD
Step 3: Enable/Disable the part of code using the macro TEST_BUILD