How to find out if a .NET assembly was compiled with the TRACE or DEBUG flag

筅森魡賤 提交于 2019-11-28 01:52:02
this. __curious_geek

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


(source: ruchitsurati.net)

LinkText: http://www.codeplex.com/AssemblyInformation

Direct link to an IsDebug tool, along with usage instructions.

static bool IsDebug(){
 bool rv = false;
 #if DEBUG
 rv = true;
 #endif
 return rv;
}

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!