How to identify if the DLL is Debug or Release build (in .NET)
Solution 1
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..
Solution 2
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:
- Open the assembly in ILDASM
- Open the Manifest
- Look at the DebuggableAttribute bitmask. If the DebuggableAttribute is not present, it is definitely an Optimized assembly.
- If it is present, look at the 4th byte - if it is a '0' it is JIT Optimized - anything else, it is not:
// 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
Related videos on Youtube
Comments
-
Djonatas Tenfen almost 2 years
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?
-
Promit about 15 yearsThis blog post has the programmatic approach.
-
Graeme Bradbury about 15 yearsA Link to another SO question on the same topic.
-
Kiquenet over 13 yearssimilars questions in Stackoverflow, one question, and many, many different answers: stackoverflow.com/questions/654450/… stackoverflow.com/questions/798971/… stackoverflow.com/questions/194616/… stackoverflow.com/questions/50900/… stackoverflow.com/questions/890459/…
-
Adam Tuliper about 13 yearsTo add my 2 cents as well - I blogged about this previously and include the various compile options: completedevelopment.blogspot.com/2009/07/…
-
Shahin Dohan over 3 yearsOne way that could work for most people is to simply open the DLL/EXE file with Notepad, and look for a path, for example search for "C:\" and you might find a path such as "C:\Source\myapp\obj\x64\Release\myapp.pdb", the "Release" shows that the build was done with Release configuration.
-
-
Rob Allen about 15 yearsNice find. Thanks for the link.
-
this. __curious_geek about 15 yearsIt has proven to be an exceptionally great tool in our development team. It's amazing!
-
Matt over 12 yearsthe tool at assemblyinformation.codeplex.com has been updated, you may wish to revise your answer
-
SUN Jiangong over 12 yearsIt supports .net frameworks < 4 ?
-
David Yates about 11 yearsI would also note that now that you know what you are looking for (thanks to Mr. Black) there are tools like Dot Peek from JetBrains that will give you this information. With Dot Peek you double click on the assembly itself in the Assembly Explorer (not any files under the assembly) and it will show you all the Assembly attributes that he is checking for with his tool. The key two being the Debuggable attribute and IsJITOptimizerDisabled missing.
-
santosh kumar patro about 10 yearsGreat tool. It resolve my issue. Thanks a lot for the help :)
-
h0r53 about 8 yearsCould you explain how you can use the programmatic approach on your DLLs? I don't see how I can get that code to open/find my DLL, unless I'm missing something. How does object[] attribs know which DLL to reference?
-
Dave Black about 8 years@CaitLANJenner - this is a snippet from a tool I wrote that does WAY more than this. I'm considering placing on Git. Anyways, in the code above, replace "ReflectedAssembly" with an instance of the Assembly you want to examine. You can do this with Assembly.LoadFrom(...) or the older (deprecated) usages - Assembly.Load(..), Assembly.LoadFile(..) or Assembly.LoadWithPartialName(..)
-
DJ van Wyk about 8 yearsThis tool must be up there with Lutz Roeder's .Net Reflector. Now I just need to find someone to convert it into a plugin for Total Commander's Lister tool.
-
user908645 almost 8 yearsnot working for win 10, failed to load "Microsoft.Owin.*"
-
Marc.2377 about 5 years@user908645 a more up-to-date fork can be found at github.com/tebjan/AssemblyInformation. I used the .msi installer. Working fine on my Win10 machine.
-
Sasha Bond almost 4 yearsdoes not work in dotnet core... both release and debug result same output: HasDebuggableAttribute True; IsJITOptimized False; BuildType Debug; DebugOutput Full
-
Dave Black over 3 years@SashaBond what doesn't work? The Manual method or the Programmatic method? Try the manual method on the assembly in question - it works for .NET Core. The code works for me on a .NET Core 3.1 console app compiled in 'Release' mode: HasDebuggableAttribute: True, IsJITOptimized: True, BuildType: Release, DebugOutput: pdb-only
-
Rodri over 3 yearsNice tool!!! working.
-
Joe Huang about 3 yearsHow to use ILSpy to see DebuggableAttribute bitmask?
-
Dave Black about 3 years@JokeHuang - I'm not specifically familiar with ILSpy as I use ILDASM that comes with .NET. But the information is stored in the assembly's metadata. So wherever you are able to view Assembly Metadata in ILSpy is where you would look.
-
Randy Burden almost 3 yearsFor a .NET Core 3.1 app, I loaded the DLL in JetBrains dotPeek (free decompiler tool), double-clicked on the assembly, and looked for the AssemblyConfiguration attribute. For Debug it displays
[assembly: AssemblyConfiguration("Debug")]
and for Release it displays[assembly: AssemblyConfiguration("Release")]
.