Reputation:
I have an application installed on my computer. How do I find out if it was compiled in DEBUG mode or not?
I've tried to use .NET Reflector, but it does not show anything specific. Here is what I see:
// Assembly APPLICATION_NAME, Version 8.0.0.15072
Location: C:\APPLICATION_FOLDER\APPLICATION_NAME.exe
Name: APPLICATION_NAME, Version=8.0.0.15072, Culture=neutral, PublicKeyToken=null
Type: Windows Application
Upvotes: 49
Views: 27444
Reputation: 8049
ZombieSheep's answer is incorrect.
My answer to this duplicate question is here: How to tell if a .NET application was compiled in DEBUG or RELEASE mode?
Be very careful - just looking at the 'assembly attributes' in the Assembly Manifest for the presence of the 'Debuggable' attribute does NOT mean that you have an assembly that is not JIT optimized. The assembly could be JIT optimized but have the Assembly Output under Advanced Build settings set to include 'full' or 'pdb-only' info - in which case the 'Debuggable' attribute will be present.
Please refer to my posts below for more info: How to Tell if an Assembly is Debug or Release and How to identify if the DLL is Debug or Release build (in .NET)
Jeff Key's application doesn't work correctly, because it identifies a "Debug" build based on if the DebuggableAttribute is present. The DebuggableAttribute is present if you compile in Release mode and choose DebugOutput to anything other than "none".
You also need to define exaclty what is meant by "Debug" vs. "Release"...
System.Diagnostics.Conditional()
attribute.Upvotes: 26
Reputation: 26033
If you're using Jetbrains ReSharper, you can browse to the assembly in Assembly Explorer and find out the configuration it was compiled with:
AssemblyConfiguration
attribute.[assembly: AssemblyConfiguration("Debug")]
, then the assembly is not optimized, compiled in Debug mode.[assembly: AssemblyConfiguration("Release")]
, then the assembly is optimized, compiled in Release mode.Upvotes: 0
Reputation: 7596
Here is the VB.Net version of the solution proposed by ZombieSheep
Public Shared Function IsDebug(Assem As [Assembly]) As Boolean
For Each attrib In Assem.GetCustomAttributes(False)
If TypeOf attrib Is System.Diagnostics.DebuggableAttribute Then
Return DirectCast(attrib, System.Diagnostics.DebuggableAttribute).IsJITTrackingEnabled
End If
Next
Return False
End Function
Public Shared Function IsThisAssemblyDebug() As Boolean
Return IsDebug([Assembly].GetCallingAssembly)
End Function
Update
This solution works for me but, as Dave Black pointed out, there may be situation where a different approach is needed.
So maybe you can also take a look a Dave Black's answer:
Upvotes: 2
Reputation: 14455
How about using Jeff Key's IsDebug utility? It is a little dated, but since you have Reflector you can decompile it and recompile it in any version of the framework. I did.
Upvotes: 2
Reputation: 1985
You're on the right path actually. If you look in the Disassembler window in reflector you will see the following line if it was built in debug mode:
[assembly: Debuggable(...)]
Upvotes: 9
Reputation: 29963
I blogged this a long time ago, and I don't know if it still valid or not, but the code is something like...
private void testfile(string file)
{
if(isAssemblyDebugBuild(file))
{
MessageBox.Show(String.Format("{0} seems to be a debug build",file));
}
else
{
MessageBox.Show(String.Format("{0} seems to be a release build",file));
}
}
private bool isAssemblyDebugBuild(string filename)
{
return isAssemblyDebugBuild(System.Reflection.Assembly.LoadFile(filename));
}
private bool isAssemblyDebugBuild(System.Reflection.Assembly assemb)
{
bool retVal = false;
foreach(object att in assemb.GetCustomAttributes(false))
{
if(att.GetType() == System.Type.GetType("System.Diagnostics.DebuggableAttribute"))
{
retVal = ((System.Diagnostics.DebuggableAttribute)att).IsJITTrackingEnabled;
}
}
return retVal;
}
Upvotes: 30