本文介绍了C#中的if / then调试VS发布指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在解决方案的属性,我必须配置设置为释放为我的唯一项目。

In Solution properties, I have Configuration set to "release" for my one and only project.

在主程序的开始,我有这样的code和它显示模式=调试。
我也有在最高层下面两行:

At the beginning of the main routine, I have this code, and it is showing "Mode=Debug".I also have these two lines at the very top:

#define DEBUG
#define RELEASE

是我测试正确的变量?

Am I testing the right variable?

#if (DEBUG)
            Console.WriteLine("Mode=Debug");
#elif (RELEASE)
            Console.WriteLine("Mode=Release");
#endif

我的目标是基于调试VS释放模式变量设置不同的默认值。

My goal is to set different defaults for variables based on debug vs release mode.

推荐答案

在您的code删除将#define DEBUG 。在构建配置中设置preprocessors针对特定版本(DEBUG / _DEBUG应VS定义的话)。

Remove the #define DEBUG in your code. Set preprocessors in the build configuration for that specific build (DEBUG/_DEBUG should be defined in VS already).

它打印模式=调试的原因是因为你的的#define 键,然后跳过 ELIF

The reason it prints "Mode=Debug" is because of your #define and then skips the elif.

此外,检查正确的方法是:

Also, the right way to check is:

#if DEBUG
    Console.WriteLine("Mode=Debug");
#else
    Console.WriteLine("Mode=Release");
#endif

不检查发布

这篇关于C#中的if / then调试VS发布指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:58