principlecsharpCritical
C# if/then directives for debug vs release
Viewed 0 times
directivesforreleasethendebug
Problem
In Solution properties, I have Configuration set to "release" for my one and only project.
At the beginning of the main routine, I have this code, and it is showing "Mode=Debug".
I also have these two lines at the very top:
Am I testing the right variable?
My goal is to set different defaults for variables based on debug vs release mode.
At the beginning of the main routine, I have this code, and it is showing "Mode=Debug".
I also have these two lines at the very top:
#define DEBUG
#define RELEASEAm I testing the right variable?
#if (DEBUG)
Console.WriteLine("Mode=Debug");
#elif (RELEASE)
Console.WriteLine("Mode=Release");
#endifMy goal is to set different defaults for variables based on debug vs release mode.
Solution
DEBUG/_DEBUG should be defined in VS already.Remove the
#define DEBUG in your code. Set preprocessors in the build configuration for that specific build.The reason it prints "Mode=Debug" is because of your
#define and then skips the elif.The right way to check is:
#if DEBUG
Console.WriteLine("Mode=Debug");
#else
Console.WriteLine("Mode=Release");
#endifDon't check for
RELEASE.Code Snippets
#if DEBUG
Console.WriteLine("Mode=Debug");
#else
Console.WriteLine("Mode=Release");
#endifContext
Stack Overflow Q#2104099, score: 942
Revisions (0)
No revisions yet.