How to check if an application is in debugging or release

I am doing some optimizations for my application, which is the cleanest way to check if the application is in DEBUG or RELEASE

+4
source share
4 answers

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

+14
source
 static class Program { public static bool IsDebugRelease { get { #if DEBUG return true; #else return false; #endif } } } 

Although, I tend to agree with itowlson.

+7
source

I want to add the following to AssemblyInfo.cs:

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

You can use ILSpy for both exe and dll. Just drag and drop the DLL \ EXE onto the sidebar of the explorer and you will see: [assembly: debug string ....

Example 1: Compile as release mode: enter image description here

Example 2: Compile as debug mode: enter image description here

0
source

All Articles