如何判断.NET应用程序是以DEBUG还是RELEASE模式编译? [英] How to tell if a .NET application was compiled in DEBUG or RELEASE mode?
本文介绍了如何判断.NET应用程序是以DEBUG还是RELEASE模式编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用。NET Reflector ,但不显示任何具体内容。这是我看到的:
// Assembly APPLICATION_NAME,版本8.0.0.15072
位置:C:\APPLICATION_FOLDER \APPLICATION_NAME.exe
名称:APPLICATION_NAME,Version = 8.0.0.15072,Culture = neutral,PublicKeyToken = null
类型:Windows应用程序
解决方案
我博客这个很久以前,我不知道它是否仍然有效,但代码是这样的...
{if(isAssemblyDebugBuild(file))
{
MessageBox.Show(String.Format({0 }似乎是一个调试版本,文件));
}
else
{
MessageBox.Show(String.Format({0}似乎是一个发布版本,文件));
}
}
private bool isAssemblyDebugBuild(string filename)
{
return isAssemblyDebugBuild(System.Reflection.Assembly.LoadFile(filename));
}
private bool isAssemblyDebugBuild(System.Reflection.Assembly assembl)
{
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;
}
}
返回retVal;
}
I have an application installed on my computer. How do I find out if it was compiled in DEBUG mode or not?
I've tried to use .NET Reflector, but it does not show anything specific. Here is what I see:
// 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
解决方案
I blogged this a long time ago, and I don't know if it still valid or not, but the code is something like...
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;
}
这篇关于如何判断.NET应用程序是以DEBUG还是RELEASE模式编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文