- Searching for the System.Diagnostics.DebuggableAttribute
- Searching for the System.Reflection.AssemblyConfigurationAttribute
- AssemblyConfigurationAttribute must be added by the programmer but is human readable.
- DebuggableAttribute is added automatically and is always present but is not human readable.
And if you double click the MANIFEST item you will get all manifest data.
Looking carefully you will find the DebuggableAttribute:
And perhaps the AssemblyConfigurationAttribute.
AssemblyConfigurationAttribute
Locate the AssemblyConfigurationAttribute – this attribute can be easily interpreted: its value can either be Debug or Release.
DebuggableAttribute
If AssemblyConfigurationAttribute is not present then we must use the DebuggableAttribute to get our goal.
Since we cannot understood the DebuggableAttribute value we have to open the assembly from another tool and read this attribute content. There’s no such tool available out-of-the-box but we can easily create a Command Line tool and use a method similar to:
private bool IsAssemblyDebugBuild(string filepath)
{
return IsAssemblyDebugBuild(Assembly.LoadFile(Path.GetFullPath(filepath)));
}
private bool IsAssemblyDebugBuild(Assembly assembly)
{
foreach (var attribute in assembly.GetCustomAttributes(false))
{
var debuggableAttribute = attribute as DebuggableAttribute;
if (debuggableAttribute != null)
{
return debuggableAttribute.IsJITTrackingEnabled;
}
}
return false;
}
or (if you prefer LINQ)
private bool IsAssemblyDebugBuild(Assembly assembly)
{
return assembly.GetCustomAttributes(false).Any(x =>
(x as DebuggableAttribute) != null ?
(x as DebuggableAttribute).IsJITTrackingEnabled : false);
}
No comments:
Post a Comment