tags:

views:

129

answers:

3

I am busy making some optimizations to a app of mine, what is the cleanest way to check if the app is in DEBUG or RELEASE

+5  A: 

At compile time or runtime? At compile time, you can use #if DEBUG. At runtime, you can use [Conditional("DEBUG")] to indicate methods that should only be called in debug builds, but whether this will be useful depends on the kind of changes you want to make between debug and release builds.

itowlson
+2  A: 
static class Program
{
    public static bool IsDebugRelease
    {
        get
        {
 #if DEBUG
            return true;
 #else
            return false;
 #endif
        }
     }
 }

Though, I tend to agree with itowlson.

Matthew Scharley
+1  A: 

I tend to put something like the following in AssemblyInfo.cs:

#if DEBUG
[assembly: AssemblyConfiguration("Debug build")]
#else
[assembly: AssemblyConfiguration("Release build")]
#endif
Joe