如何判断.NET应用程序是在DEBUG或RELEASE模式下编译的? [英] How to tell if a .NET application was compiled in DEBUG or RELEASE mode?

查看:233
本文介绍了如何判断.NET应用程序是在DEBUG或RELEASE模式下编译的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的计算机上安装了一个应用程序。我如何知道它是否在调试模式下编译?

I have an application installed on my computer. How do I find out if it was compiled in DEBUG mode or not?

我试图使用。NET Reflector ,但它没有显示任何具体的。这是我看到的:

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


推荐答案

blogged 这很久以前,我不知道它是否仍然有效,但代码是像... ...

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆