0
Answer

Issue with Precompiler Directive

Chad

Chad

14y
2.1k
1

So I have a simple case where I am trying to using a precompile directive to conditionally execute one line of code.  Say my code looks like this:
#define BLUE
// ...
#if BLUE
    Console.WriteLine("BLUE version");
#endif

So I created a custom build configuration called MyConfig (that copies settings from the RELEASE configuration).  If I go to my project properties of the project that has the code above, and select the MyConfig configuration, I add the Conditional Compilation Symbol "BLUE".  My thought is that the conditional line should only get executed when the solution is build from the MyConfig configuration. 
As a test, I just build the solution in DEBUG model, and set a breakpoint on the code above.  Much to my surprise, it actually executed the Console.WriteLine.  It seems like everything is configured correclty.  Does it look like I did something wrong?
At the end of the day, under most circumstances, I do NOT want the line of code executed.  But since my test failed, I am worried that the line could get executed no matter what configuration I build from.
Any thoughts?