Software Release / Debug Mode Definition (.NET)

Possible duplicate:
How to find out if a .NET assembly was built using the TRACE or DEBUG flag

Possible duplicate:
How to determine if a DLL is a version of Debug or Release (in .NET)

What is the easiest way to programmatically check if the current build has been compiled in debug or release mode?

+55
debugging release
Mar 17 '09 at 14:19
source share
2 answers
bool isDebugMode = false; #if DEBUG isDebugMode = true; #endif 

If you want to program different behaviors between debug and release builds, you must do this as follows:

 #if DEBUG int[] data = new int[] {1, 2, 3, 4}; #else int[] data = GetInputData(); #endif int sum = data[0]; for (int i= 1; i < data.Length; i++) { sum += data[i]; } 

Or, if you want to perform certain checks on debug versions of functions, you can do it like this:

 public int Sum(int[] data) { Debug.Assert(data.Length > 0); int sum = data[0]; for (int i= 1; i < data.Length; i++) { sum += data[i]; } return sum; } 

Debug.Assert will not be included in the release build.

+112
Mar 17 '09 at 14:21
source share

I hope this will be useful for you:

 public static bool IsRelease(Assembly assembly) { object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), true); if (attributes == null || attributes.Length == 0) return true; var d = (DebuggableAttribute)attributes[0]; if ((d.DebuggingFlags & DebuggableAttribute.DebuggingModes.Default) == DebuggableAttribute.DebuggingModes.None) return true; return false; } public static bool IsDebug(Assembly assembly) { object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), true); if (attributes == null || attributes.Length == 0) return true; var d = (DebuggableAttribute)attributes[0]; if (d.IsJITTrackingEnabled) return true; return false; } 
+13
Mar 17 '09 at 14:22
source share



All Articles