C# 配置中debug 和活动(debug)区别

新手,谢谢... 新手,谢谢 展开
 我来答
xiangjuan314
2016-01-15 · TA获得超过3.3万个赞
知道大有可为答主
回答量:2.9万
采纳率:0%
帮助的人:2760万
展开全部
Debug (配置中debug)通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程
序。
Release (活动(debug))称为发布版本,它往往是进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以便用户很好地使用。
Debug 和 Release 的真正秘密,在于一组编译选项。下面列出了分别针对二者的选项(当然除此之外还有其他一些,如/Fd /Fo,但区别并不重要,通常他们也不会引起 Release 版错误,在此不讨论)

Debug 版本:
1./MDd /MLd 或 /MTd 使用 Debug runtime library(调试版本的运行时刻函数库)
2./Od 关闭优化开关
3./D "_DEBUG" 相当于 #define _DEBUG,打开编译调试代码开关(主要针对assert函数)
4./ZI 创建 Edit and continue(编辑继续)数据库,这样在调试过程中如果修改了源代码不需重新编译
5./GZ 可以帮助捕获内存错误
6./Gm 打开最小化重链接开关,减少链接时间

Release 版本:
1./MD /ML 或 /MT 使用发布版本的运行时刻函数库
2./O1 或 /O2 优化开关,使程序最小或最快
3./D "NDEBUG" 关闭条件编译调试代码开关(即不编译assert函数)
4./GF 合并重复的字符串,并将字符串常量放到只读内存,防止被修改

实际上,Debug 和 Release 并没有本质的界限,他们只是一组编译选项的集合,编译器只是按照预定的选项行动。事实上,甚至可以修改这些选项,从而得到优化过的调试版本或是带跟踪语句的发布版本。

C#中的两种debug方法介绍
第一种:需要把调试方法改成debug
代码用 #if DEBUG 包裹
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SplitPackage
{
public static class EnvConfig
{
static EnvConfig()
{
#if DEBUG
ToolsPath = @"D:\workspace\shopstyle\tool";
#else
ToolsPath = Environment.CurrentDirectory;
#endif
int rootIdx = ToolsPath.LastIndexOf(@"\");
if (rootIdx > 0)
{
RootPath = ToolsPath.Substring(0, rootIdx);
}
}
public static string ToolsPath { get; private set; }
public static string TmplateFile { get { return Path.Combine(ToolsPath, @"template\default.pm"); } }
public static string RootPath { get; private set; }
public static string ModulePath { get { return Path.Combine(RootPath, "module"); } }
public static string ConfigPath { get { return Path.Combine(RootPath, "conf"); } }

}
}

第二种:利用宏定义
#define DEBUG// C#的宏定义必须出现在所有代码之前。当前我们只让DEBUG宏有效。
using System.Diagnostics; //必须包含这个包
#define DEBUG
using System.Diagnostics;
namespace TestConsole
{
class ToolKit
{
[ConditionalAttribute("LI")] // Attribute名称的长记法
[ConditionalAttribute("DEBUG")]
public static void Method1() { Console.WriteLine("Created By Li, Buged.11"); }

[ConditionalAttribute("LI")]
[ConditionalAttribute("NOBUG")]
public static void Method2() { Console.WriteLine("Created By Li, NoBug."); }

[Conditional("ZHANG")] // Attribute名称的短记法
[Conditional("DEBUG")]
public static void Method3() { Console.WriteLine("Created By Zhang, Buged.11"); }

[Conditional("ZHANG")]
[Conditional("NOBUG")]
public static void Method4() { Console.WriteLine("Created By Zhang, NoBug."); }
}
static void Main(string[] args)
{
ToolKit.Method1();
ToolKit.Method2();
ToolKit.Method3();
ToolKit.Method4();
}
}
}
火鸟无生
2021-10-06
知道答主
回答量:2
采纳率:0%
帮助的人:933
引用xiangjuan314的回答:
Debug (配置中debug)通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程
序。
Release (活动(debug))称为发布版本,它往往是进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以便用户很好地使用。
Debug 和 Release 的真正秘密,在于一组编译选项。下面列出了分别针对二者的选项(当然除此之外还有其他一些,如/Fd /Fo,但区别并不重要,通常他们也不会引起 Release 版错误,在此不讨论)

Debug 版本:
1./MDd /MLd 或 /MTd 使用 Debug runtime library(调试版本的运行时刻函数库)
2./Od 关闭优化开关
3./D "_DEBUG" 相当于 #define _DEBUG,打开编译调试代码开关(主要针对assert函数)
4./ZI 创建 Edit and continue(编辑继续)数据库,这样在调试过程中如果修改了源代码不需重新编译
5./GZ 可以帮助捕获内存错误
6./Gm 打开最小化重链接开关,减少链接时间

Release 版本:
1./MD /ML 或 /MT 使用发布版本的运行时刻函数库
2./O1 或 /O2 优化开关,使程序最小或最快
3./D "NDEBUG" 关闭条件编译调试代码开关(即不编译assert函数)
4./GF 合并重复的字符串,并将字符串常量放到只读内存,防止被修改

实际上,Debug 和 Release 并没有本质的界限,他们只是一组编译选项的集合,编译器只是按照预定的选项行动。事实上,甚至可以修改这些选项,从而得到优化过的调试版本或是带跟踪语句的发布版本。

C#中的两种debug方法介绍
第一种:需要把调试方法改成debug
代码用 #if DEBUG 包裹
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SplitPackage
{
public static class EnvConfig
{
static EnvConfig()
{
#if DEBUG
ToolsPath = @"D:\workspace\shopstyle\tool";
#else
ToolsPath = Environment.CurrentDirectory;
#endif
int rootIdx = ToolsPath.LastIndexOf(@"\");
if (rootIdx > 0)
{
RootPath = ToolsPath.Substring(0, rootIdx);
}
}
public static string ToolsPath { get; private set; }
public static string TmplateFile { get { return Path.Combine(ToolsPath, @"template\default.pm"); } }
public static string RootPath { get; private set; }
public static string ModulePath { get { return Path.Combine(RootPath, "module"); } }
public static string ConfigPath { get { return Path.Combine(RootPath, "conf"); } }

}
}

第二种:利用宏定义
#define DEBUG// C#的宏定义必须出现在所有代码之前。当前我们只让DEBUG宏有效。
using System.Diagnostics; //必须包含这个包
#define DEBUG
using System.Diagnostics;
namespace TestConsole
{
class ToolKit
{
[ConditionalAttribute("LI")] // Attribute名称的长记法
[ConditionalAttribute("DEBUG")]
public static void Method1() { Console.WriteLine("Created By Li, Buged.11"); }

[ConditionalAttribute("LI")]
[ConditionalAttribute("NOBUG")]
public static void Method2() { Console.WriteLine("Created By Li, NoBug."); }

[Conditional("ZHANG")] // Attribute名称的短记法
[Conditional("DEBUG")]
public static void Method3() { Console.WriteLine("Created By Zhang, Buged.11"); }

[Conditional("ZHANG")]
[Conditional("NOBUG")]
public static void Method4() { Console.WriteLine("Created By Zhang, NoBug."); }
}
static void Main(string[] args)
{
ToolKit.Method1();
ToolKit.Method2();
ToolKit.Method3();
ToolKit.Method4();
}
}
}
展开全部
release后面括号里应该是“活动release",而且没有真正回答debug和活动debug的区别,答非所问。看来大多数人还是不懂,浑浑噩噩、似懂非懂啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
阳光的雷咩咩
2014-12-18 · TA获得超过1.4万个赞
知道大有可为答主
回答量:2.3万
采纳率:66%
帮助的人:7567万
展开全部
既然是新手,管这么多干嘛,影响你编程序了吗?VS里那么多选项你都要一一弄懂才开始学具体的代码?
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式