c# 判断当前版本是Debugger或Release

1.第一种 (常用)

#if DEBUG

   //debugger 环境

#else
  //release 环境
#endif

  

2. 第二种

private bool IsDebug()
        {
            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;
                    }
                }
            }
            return debug;
        }

  

原文地址:https://www.cnblogs.com/zxhome/p/10748355.html