如何判断一个.NET应用程序是在调试或发布模式下编译?是在、应用程序、如何判断、模式下

2023-09-02 10:19:31 作者:毕竟念旧

我已经安装在计算机上的应用程序。如何才能知道,如果它被编译在调试模式或不?

我试着使用 .net反射,但它并没有显示具体的东西。这是我所看到的:

  //大会APPLICATION_NAME,版本8.0.0.15072
位置:C: APPLICATION_FOLDER  APPLICATION_NAME.exe
名称:APPLICATION_NAME,版本= 8.0.0.15072,文化=中性公钥=空
类型:Windows应用程序
 

解决方案

我是很久以前的博客这一点,我不知道它是否仍然有效与否,而是code是一样的东西......

 私人无效testfile的(字符串的文件)
{
    如果(isAssemblyDebugBuild(文件))
    {
    的MessageBox.show(的String.Format({0}似乎是一个调试版本,文件));
    }
    其他
    {
    的MessageBox.show(的String.Format({0}似乎是一个发布版本,文件));
    }
}

私人布尔isAssemblyDebugBuild(字符串文件名)
{
    返回isAssemblyDebugBuild(System.Reflection.Assembly.LoadFile(文件名));
}

私人布尔isAssemblyDebugBuild(System.Reflection.Assembly assemb)
{
    布尔retVal的= FALSE;
    的foreach(在assemb.GetCustomAttributes对象ATT(假))
    {
    如果(att.GetType()== System.Type.GetType(System.Diagnostics.DebuggableAttribute))
    {
    retVal的=((System.Diagnostics.DebuggableAttribute)ATT).IsJITTrackingEnabled;
    }
    }
    返回retVal的;
}
 

.NET应用程序调试 原理 工具 方法 多图 精华

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_FOLDERAPPLICATION_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;
}