How to tell if a .NET application was compiled in DEBUG or RELEASE mode?

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

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;
}

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"...

  • Do you mean that the application is configured with code optimization?
  • Do you mean that you can attach the Visual Studio/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.

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(...)]

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.