问题
Possible Duplicate:
How to tell if a .NET application was compiled in DEBUG or RELEASE mode?
I\'m sure this has been asked before, but google and SO search failed me.
How can I identify if a DLL is a release build or debug build?
回答1:
The only best way to do this is to check the compiled assemblies itself. There is this very useful tool called '.NET Assembly Information' found here by Rotem Bloom. After you install this, it associates itself with .dll files to open with itself. After installing you can just double-click on the Assembly to open and it will give you the assembly details as displayed in the screenshots below. There you can identify if it's debug compiled or not.
Hope this helps..
回答2:
IMHO, The above application is really misleading; it only looks for the IsJITTrackingEnabled which is completely independent of whether or not the code is compiled for optimization and JIT Optimization.
The DebuggableAttribute is present if you compile in Release mode and choose DebugOutput to anything other than "none".
You also need to define exactly what is meant by "Debug" vs. "Release"...
Do you mean that the app is configured with code optimization? Do you mean that you can attach the VS/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.
IMHO, when someone asks whether or not an assembly is "Debug" or "Release", they really mean if the code is optimized...
Sooo, do you want to do this manually or programmatically?
Manually: You need to view the value of the DebuggableAttribute bitmask for the assembly's metadata. Here's how to do it:
- Open the assembly in ILDASM
- Open the Manifest
- Look at the DebuggableAttribute bitmask. If the DebuggableAttribute is not present, it is definitely an Optimized assembly.
- If it is present, look at the 4th byte - if it is a '0' it is JIT Optimized - anything else, it is not:
// Metadata version: v4.0.30319 .... // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 )
Programmatically: assuming that you want to know programmatically if the code is JITOptimized, here is the correct implementation:
object[] attribs = ReflectedAssembly.GetCustomAttributes(typeof(DebuggableAttribute),
false);
// If the 'DebuggableAttribute' is not found then it is definitely an OPTIMIZED build
if (attribs.Length > 0)
{
// Just because the 'DebuggableAttribute' is found doesn't necessarily mean
// it's a DEBUG build; we have to check the JIT Optimization flag
// i.e. it could have the "generate PDB" checked but have JIT Optimization enabled
DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute;
if (debuggableAttribute != null)
{
HasDebuggableAttribute = true;
IsJITOptimized = !debuggableAttribute.IsJITOptimizerDisabled;
BuildType = debuggableAttribute.IsJITOptimizerDisabled ? "Debug" : "Release";
// check for Debug Output "full" or "pdb-only"
DebugOutput = (debuggableAttribute.DebuggingFlags &
DebuggableAttribute.DebuggingModes.Default) !=
DebuggableAttribute.DebuggingModes.None
? "Full" : "pdb-only";
}
}
else
{
IsJITOptimized = true;
BuildType = "Release";
}
I've provided this implementation on my blog at:
How to Tell if an Assembly is Debug or Release
来源:https://stackoverflow.com/questions/798971/how-to-identify-if-the-dll-is-debug-or-release-build-in-net