Friday, January 20, 2012

How to check if an assembly was compiled in debug mode?

The following method will let you know if the assembly was compiled in debug mode or in release mode:



private bool IsAssemblyBuiltInDebugMode(string filepath)
        {
            return IsAssemblyBuiltInDebugMode(Assembly.LoadFile(Path.GetFullPath(filepath)));
        }
        private bool IsAssemblyBuiltInDebugMode(Assembly assembly)
        {
            foreach (var attribute in assembly.GetCustomAttributes(false))
            {
                var debuggableAttribute = attribute as DebuggableAttribute;
                if (debuggableAttribute != null)
                {
                    return debuggableAttribute.IsJITTrackingEnabled;
                }
            }
            return false;
        }
This is in reference to the article http://www.codeproject.com/Articles/72504/NET-Determine-Whether-an-Assembly-was-compiled-in

No comments:

Post a Comment