【问题标题】:Asp.net release build vs debug buildAsp.net 发布版本与调试版本
【发布时间】:2010-10-27 18:55:49
【问题描述】:

如何确定我的应用程序是否编译为“发布”而不是“调试”?我去了 VS 2008 Project Properties > Build 并将配置从 Debug 设置为 Release,但我注意到没有变化?这是一个 ASP.NET 项目。

【问题讨论】:

标签: asp.net build debugging release


【解决方案1】:

您需要寻找的不仅仅是 IsJITTrackingEnabled - 它完全独立于代码是否为优化和 JIT 优化而编译。

此外,如果您在 Release 模式下编译并选择 DebugOutput 为“none”以外的任何内容,则会出现 DebuggableAttribute。

请参考我的帖子: How to Tell if an Assembly is Debug or ReleaseHow to identify if the DLL is Debug or Release build (in .NET)

【讨论】:

    【解决方案2】:

    如果你想知道 dll 是否是在调试模式下构建的,带有调试属性,那么你最好的选择是反射。

    取自“How to tell if an existing assembly is debug or release”:

    Assembly assembly = Assembly.GetAssembly(GetType());
    bool debug = false;
    foreach (var attribute in assembly.GetCustomAttributes(false)){
      if (attribute.GetType() ==  typeof(System.Diagnostics.DebuggableAttribute)){
        if (((System.Diagnostics.DebuggableAttribute)attribute)
            .IsJITTrackingEnabled){
          debug = true;
          break;
        }
      }
    }
    

    这将获取调用该代码的程序集(实际上是本身),然后如果程序集是在调试模式下编译的,则将调试布尔值设置为 true,否则为 false。

    这可以很容易地放入控制台应用程序中(如链接示例中所示),然后传入要检查的 dll/exe 的路径。您可以从如下路径加载程序集:

    Assembly assembly = 
        Assembly.LoadFile(System.IO.Path.GetFullPath(m_DllPath.Text));
    

    【讨论】:

      【解决方案3】:
      【解决方案4】:

      对于 Web.config 中的一个调试将设置为 true,但是您实际上也可以在发布应用程序中设置它。

      然而,在调试中设置了 DEBUG 之类的定义,所以它很简单:

      bool is_debug;
      
      #ifdef DEBUG
      is_debug = true;
      #else
      is_debug = false;
      #endif
      

      【讨论】:

      • 调试仅在您明确设置时在 Web.config 中设置,或者您按 F5 运行网站并允许它更改配置文件。此设置不是选择构建配置的指标。
      • 你确定吗?嗯嗯嗯嗯然后:/
      猜你喜欢
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      • 2011-04-16
      相关资源
      最近更新 更多