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