45 .net executable debug-symbols compiler-options
我的计算机上安装了一个应用程序.如何确定它是否在DEBUG模式下编译?
我曾尝试使用.NET Reflector,但它没有显示任何具体内容.这是我看到的:
// Assembly APPLICATION_NAME, Version 8.0.0.15072
Location: C:\APPLICATION_FOLDER\APPLICATION_NAME.exe
Name: APPLICATION_NAME, Version=8.0.0.15072, Culture=neutral, PublicKeyToken=null
Type: Windows Application
Run Code Online (Sandbox Code Playgroud)
Zom*_*eep 29
我很久以前在博客上发帖,我不知道它是否仍然有效,但代码是......
private void testfile(string file)
{
if(isAssemblyDebugBuild(file))
{
MessageBox.Show(String.Format("{0} seems to be a debug build",file));
}
else
{
MessageBox.Show(String.Format("{0} seems to be a release build",file));
}
}
private bool isAssemblyDebugBuild(string filename)
{
return isAssemblyDebugBuild(System.Reflection.Assembly.LoadFile(filename));
}
private bool isAssemblyDebugBuild(System.Reflection.Assembly assemb)
{
bool retVal = false;
foreach(object att in assemb.GetCustomAttributes(false))
{
if(att.GetType() == System.Type.GetType("System.Diagnostics.DebuggableAttribute"))
{
retVal = ((System.Diagnostics.DebuggableAttribute)att).IsJITTrackingEnabled;
}
}
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*ack 26
ZombieSheep的回答是不正确的.
我对这个重复问题的回答如下:如何判断.NET应用程序是在DEBUG还是RELEASE模式下编译的?
要非常小心-只是在"程序集属性"在大会清单为"可调试"属性的存在确实不意味着你有没有JIT优化的装配.程序集可以进行JIT优化,但将Advanced Build设置下的Assembly Output设置为包含'full'或'pdb-only'信息 - 在这种情况下,将出现'Debuggable'属性.
有关更多信息,请参阅下面的帖子: 如何判断程序集是否为调试或发布以及 如何识别DLL是否为Debug或Release版本(在.NET中)
Jeff Key的应用程序无法正常工作,因为它根据DebuggableAttribute是否存在来识别"Debug"构建.如果在Release模式下编译并选择DebugOutput为"none"以外的任何值,则存在DebuggableAttribute.
您还需要定义exaclty "Debug"与"Release"的含义...
System.Diagnostics.Conditional()属性有条件地编译方法.你实际上是在正确的道路上.如果您在反射器中查看反汇编程序窗口,如果它是在调试模式下构建的,您将看到以下行:
[assembly: Debuggable(...)]
Run Code Online (Sandbox Code Playgroud)