+ -
当前位置:首页 → 问答吧 → vb.net 怎么判断生成的exe 是debug还是release版本的。

vb.net 怎么判断生成的exe 是debug还是release版本的。

时间:2011-12-20

来源:互联网

vb.net 用程序 怎么判断生成的exe 是debug还是release版本的。

作者: liyanmingkong   发布时间: 2011-12-20

该回复于2011-12-20 11:36:12被管理员删除

  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
#2楼 得分:0回复于:2011-12-20 11:45:47
在.NET中以DebuggableAttribute来控制CLR如何处理模块代码规则,
而属性IsJITTrackingEnabled来标识运行库在代码生成过程中是否跟踪调试信息的的标识,
如果IsJITTrackingEnabled为True,表示运行库跟踪调试信息,可推断为Debug Build 模式;
如果IsJITTrackingEnabled为false,表示运行库没有跟踪调试信息,可推断为Release模式。
所以,解决方法着眼于对IsJITTrackingEnabled信息的获取上: 具体解决方法: 
public enum DebugMode 

  Debug, 
  Release 

public static class Utils 

  /// <summary> 
  /// Get GetCustomAttribute 
  /// </summary> 
  /// <typeparam name="T">CustomAttribute Type</typeparam> 
  /// <param name="provider"></param> 
  /// <returns></returns> 
  public static T GetCustomAttribute<T>(this ICustomAttributeProvider provider) where T : Attribute 
  { 
  var attributes = provider.GetCustomAttributes(typeof(T), false); 
  return attributes.Length > 0 ? attributes[0] as T : default(T); 
  } 
  
  public static DebugMode GetDebugMode(string assemblyName) 
  { 
  if (string.IsNullOrEmpty(assemblyName)) 
  { 
  throw new ArgumentNullException("assemblyName"); 
  } 
  DebugMode ret = DebugMode.Debug; 
  try 
  {
  // Get assebly by name Assembly ass = Assembly.LoadFile(assemblyName); 
  // Get DebuggableAttribute info DebuggableAttribute att = ass.GetCustomAttribute<DebuggableAttribute>(); 
  ret = att.IsJITTrackingEnabled ? DebugMode.Debug : DebugMode.Release; 
  } catch (Exception) 
  { 
  throw; 
  } 
  return ret; 
  } 
}

作者: liyanmingkong   发布时间: 2011-12-20

作者: gxingmin   发布时间: 2011-12-20

thank you ,试一下。

作者: gxingmin   发布时间: 2011-12-20

相关阅读 更多