Asp.net发布构建与调试构建

时间:2009-05-20 21:54:44

标签: asp.net build debugging release

如何确定我的应用是否已编译为“发布”而非“调试”?我去了VS 2008 Project Properties>构建并将配置从Debug设置为Release但是我发现没有变化?这是一个ASP.NET项目。

4 个答案:

答案 0 :(得分:4)

答案 1 :(得分:3)

如果你想知道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;
    }
  }
}

这将获得调用该代码的程序集(实际上是自身),然后如果程序集是在调试模式下编译的话,则将debug boolean设置为true,否则为false。

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

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

答案 2 :(得分:1)

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

在debug中,但是设置了像DEBUG这样的定义,所以它很简单:

bool is_debug;

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

答案 3 :(得分:0)

您需要查找的不仅仅是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)