Possible Duplicate:
How to tell if a .NET application was compiled in DEBUG or RELEASE mode?
I'm sure this has been asked before, but google and SO search failed me.
How can I identify if a DLL is a release build or debug build?
Check your project's build settings under 'Apple LLVM - Preprocessing', 'Preprocessor Macros' for debug to ensure that DEBUG is being set - do this by selecting the project and clicking on the build settings tab. Search for DEBUG and look to see if indeed DEBUG is being set.
IMHO, The above application is really misleading; it only looks for the IsJITTrackingEnabled which is completely independent of whether or not the code is compiled for optimization and JIT Optimization.
The DebuggableAttribute is present if you compile in Release mode and choose DebugOutput to anything other than "none".
You also need to define exactly what is meant by "Debug" vs. "Release"...
Do you mean that the app is configured with code optimization? Do you mean that you can attach the VS/JIT Debugger to it? Do you mean that it generates DebugOutput? Do you mean that it defines the DEBUG constant? Remember that you can conditionally compile Methods with the System.Diagnostics.Conditional() attribute.
IMHO, when someone asks whether or not an assembly is "Debug" or "Release", they really mean if the code is optimized...
Sooo, do you want to do this manually or programmatically?
Manually: You need to view the value of the DebuggableAttribute bitmask for the assembly's metadata. Here's how to do it:
// Metadata version: v4.0.30319 .... // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 )
Programmatically: assuming that you want to know programmatically if the code is JITOptimized, here is the correct implementation (in a simple console app):
void Main() { var HasDebuggableAttribute = false; var IsJITOptimized = false; var IsJITTrackingEnabled = false; var BuildType = ""; var DebugOutput = ""; var ReflectedAssembly = Assembly.LoadFile(@"path to the dll you are testing"); object[] attribs = ReflectedAssembly.GetCustomAttributes(typeof(DebuggableAttribute), false); // If the 'DebuggableAttribute' is not found then it is definitely an OPTIMIZED build if (attribs.Length > 0) { // Just because the 'DebuggableAttribute' is found doesn't necessarily mean // it's a DEBUG build; we have to check the JIT Optimization flag // i.e. it could have the "generate PDB" checked but have JIT Optimization enabled DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute; if (debuggableAttribute != null) { HasDebuggableAttribute = true; IsJITOptimized = !debuggableAttribute.IsJITOptimizerDisabled; // IsJITTrackingEnabled - Gets a value that indicates whether the runtime will track information during code generation for the debugger. IsJITTrackingEnabled = debuggableAttribute.IsJITTrackingEnabled; BuildType = debuggableAttribute.IsJITOptimizerDisabled ? "Debug" : "Release"; // check for Debug Output "full" or "pdb-only" DebugOutput = (debuggableAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.Default) != DebuggableAttribute.DebuggingModes.None ? "Full" : "pdb-only"; } } else { IsJITOptimized = true; BuildType = "Release"; } Console.WriteLine($"{nameof(HasDebuggableAttribute)}: {HasDebuggableAttribute}"); Console.WriteLine($"{nameof(IsJITOptimized)}: {IsJITOptimized}"); Console.WriteLine($"{nameof(IsJITTrackingEnabled)}: {IsJITTrackingEnabled}"); Console.WriteLine($"{nameof(BuildType)}: {BuildType}"); Console.WriteLine($"{nameof(DebugOutput)}: {DebugOutput}"); }
I've provided this implementation on my blog at:
How to Tell if an Assembly is Debug or Release
The only best way to do this is to check the compiled assemblies itself. There is this very useful tool called '.NET Assembly Information' found here by Rotem Bloom. After you install this, it associates itself with .dll files to open with itself. After installing you can just double-click on the Assembly to open and it will give you the assembly details as displayed in the screenshots below. There you can identify if it's debug compiled or not.
Hope this helps..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With