Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

(C#) Determining whether the current build mode is Debug or Release

5.00/5 (2 votes)
1 Feb 2012CPOL 16.2K  
Have a look this one, I just wrote: Accurate way to tell if an assembly is compiled in debug or release mode in c#[^] public static bool IsInDebugMode(string FileName) { var assembly = System.Reflection.Assembly.LoadFile(FileName); var attributes =...
Have a look this one, I just wrote: Accurate way to tell if an assembly is compiled in debug or release mode in c#[^]


C#
public static bool IsInDebugMode(string FileName)
{
    var assembly = System.Reflection.Assembly.LoadFile(FileName);
    var attributes = assembly.GetCustomAttributes(typeof(System.Diagnostics.DebuggableAttribute), false);
    if (attributes.Length > 0)
    {
        var debuggable = attributes[0] as System.Diagnostics.DebuggableAttribute;
        if (debuggable != null)
            return (debuggable.DebuggingFlags & System.Diagnostics.DebuggableAttribute.DebuggingModes.Default) == System.Diagnostics.DebuggableAttribute.DebuggingModes.Default;
        else
            return false;
    }
    else
        return false;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)