Coder Perfect

Will #if RELEASE behave similarly to #if DEBUG in C#?


“DEBUG” is used in every case of the #if compiler directive that I’ve seen. Can I use “RELEASE” in the same way to exclude code from debug mode compilation that I don’t want to run? The code I want to enclose with this block sends out a lot of emails, which I don’t want to send out by accident when testing.

Asked by Brian Sullivan

Solution #1

Although RELEASE isn’t defined, you can use it.

#if (!DEBUG)

Answered by M4N

Solution #2

No, unless you put in some effort.

The crucial thing is to understand what DEBUG is, which is a kind of defined constant that the compiler can verify against.

Three things can be found in the project properties, under the Build tab:

There is no such checkbox, nor constant/symbol pre-defined that has the name RELEASE.

Before doing so, make sure the project configuration is set to Release-mode, as these adjustments are per configuration.

So, unless you include that in the text field, #if RELEASE will not generate any code in any configuration.

Answered by Lasse V. Karlsen

Solution #3


There is a DEBUG specified constant (automatically defined by Visual Studio) in debug mode, but no such constant is defined in release mode. Under build, look at your project’s settings.

When you select [Define DEBUG constant] from Project -> Build, it’s the same as including #define DEBUG at the top of every file.

To define a RELEASE constant for the release configuration, navigate to:

Answered by Pop Catalin

Solution #4

#if RELEASE does not work on my VS installation (VS 2008). You might, however, just use #if! DEBUG


#if !DEBUG

Answered by JaredPar

Solution #5

That’s something I’ve never seen before…but I have seen:

#if (DEBUG == FALSE)


#if (!DEBUG)

Is that what you’re looking for?

Answered by Pete H.

Post is based on