C#判断一个.net可执行文件时release版本还是debug版本的代码

347 阅读1分钟

把写内容过程经常用的一些内容备份一下,如下内容段是关于C#判断一个.net可执行文件时release版本还是debug版本的内容。

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

其它文件检测 Assembly assembly = Assembly.LoadFile(System.IO.Path.GetFullPath(m_DllPath.Text)); 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; } } }