Is there any way to find out if an assembly has been compiled with the TRACE or DEBUG flag set without modifying the assembly?
问题:
回答1:
The only best way to do is 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 asociates .dll files to open with itself. After installing you can just double-click on the Assembly to open with it and it will give you the assembly details as displayed in the screenshop below. There you can identify if it's debug compiled or not.
alt text http://ruchitsurati.net/myfiles/asm_info.jpg
alt text http://ruchitsurati.net/myfiles/release_assembly.PNG
LinkText: http://www.codeplex.com/AssemblyInformation
回答2:
How to Programmatically Detect if an Assembly is Compiled in Debug or Release mode from Scott Hanselman.
回答3:
Direct link to an IsDebug tool, along with usage instructions.
回答4:
static bool IsDebug(){
bool rv = false;
#if DEBUG
rv = true;
#endif
return rv;
}
回答5:
There is probably no generic way. However, you could look for references to Assert
and Debug
from the System.Diagnostics
namespace. Presence of those will indicate that the DEBUG flag was set.
The same holds for Trace
and the TRACE flag.
Obviously this won't work if the source code does not use types from these namespaces.
回答6:
The "IsDebug" app mentioned above, actually has a bug in it where it doesn't reflect on the correct DubuggableAttributes. It incorrectly assumes that if the DebuggableAttribute is present, then the assembly is not JIT Optimized. I've provided a correct implementation on my blog at:
How to Tell if an Assembly is Debug or Release