.net not working - Will #if RELEASE work like #if DEBUG does in C#?





5 Answers

RELEASE is not defined, but you can use

#if (!DEBUG)
  ...
#endif
preprocessor directives best

In all the examples I've seen of the #if compiler directive, they use "DEBUG". Can I use "RELEASE" in the same way to exclude code that I don't want to run when compiled in debug mode? The code I want to surround with this block sends out a bunch of emails, and I don't want to accidentally send those out when testing.




On my VS install (VS 2008) #if release does not work. However you could just use !DEBUG

Example:

#if !DEBUG
SendTediousEmail()
#endif



You can use #if(!DEBUG) for this purposes.




I know this is an old question, but it might be worth mentioning that you can create your own configurations outside of DEBUG and RELEASE, such as TEST or UAT.

If then on the Build tab of the project properties page you then set the "Conditional compilation symbols" to TEST (for instance) you can then use a construct such as

#if (DEBUG || TEST )
    //Code that will not be executed in RELEASE or UAT
#endif

You can use this construct for specific reason such as different clients if you have the need, or even entire Web Methods for instance. We have also used this in the past where some commands have caused issues on specific hardware, so we have a configuration for an app when deployed to hardware X.




why not just

#if RELEASE
#undef DEBUG
#endif



Related