65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Feb 1, 2012

CPOL
viewsIcon

16287

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#[^]
        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;
        }