如何识别 DLL 是调试版本还是发布版本(在 .NET 中)
我确信之前已经有人问过这个问题,但是 google 和 SO 搜索让我失败了。
如何识别 DLL 是发布版本还是调试版本?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恕我直言,上述应用程序确实具有误导性; 它只查找 IsJITTrackingEnabled,它完全独立于代码是否经过编译以进行优化和 JIT 优化。
如果您在发布模式下编译并选择 DebugOutput 为“none”以外的任何值,则 DebuggableAttribute 会出现。
您还需要准确定义“调试”与“发布”的含义...
您的意思是应用程序配置了代码优化吗?
您的意思是可以将 VS/JIT 调试器附加到它吗?
你的意思是它生成 DebugOutput 吗?
您的意思是它定义了 DEBUG 常量吗? 请记住,您可以使用 System.Diagnostics.Conditional() 属性有条件地编译方法。
恕我直言,当有人问程序集是否是“调试”或“发布”时,他们的真正意思是代码是否经过优化……
那么,您想手动还是以编程方式执行此操作?
手动:
您需要查看程序集元数据的 DebuggableAttribute 位掩码的值。 操作方法如下:
以编程方式:假设您想以编程方式了解代码是否经过 JITOptimized,这是正确的实现(在简单的控制台应用程序中) :
我在我的博客上提供了此实现:
如何判断程序集是调试还是发布
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:
Programmatically: assuming that you want to know programmatically if the code is JITOptimized, here is the correct implementation (in a simple console app):
I've provided this implementation on my blog at:
How to Tell if an Assembly is Debug or Release
执行此操作的唯一最佳方法是检查已编译的程序集本身。 Rotem Bloom 在此处找到了一个非常有用的工具,名为“.NET Assembly Information”。 安装后,它会将自身与 .dll 文件关联起来以自行打开。 安装后,您只需双击程序集即可打开,它将为您提供程序集详细信息,如下面的屏幕截图所示。 在那里您可以确定它是否经过调试编译。
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.