将#IF发布工作就像#如果调试不使用C#?就像、工作、IF

2023-09-02 01:37:57 作者:莫名的曖昧

在我所见过的#如果编译器指令的例子,他们使用调试。我是否可以使用释放以同样的方式来排除我不想在调试模式编译运行code?在code我想围绕这个块发出了一堆邮件,我不想在测试时不小心把那些了。

In all the examples I've seen of the #if compiler directive, they use "DEBUG". Can I use "RELEASE" in the same way to exclude code that I don't want to run when compiled in debug mode? The code I want to surround with this block sends out a bunch of emails, and I don't want to accidentally send those out when testing.

推荐答案

没有,也不会,除非你做一些工作。

No, it won't, unless you do some work.

这里最重要的部分是什么DEBUG真的是,和它的定义,编译器可以检查对一种恒定的。

The important part here is what DEBUG really is, and it's a kind of constant defined that the compiler can check against.

如果您检查项目属性,生成选项卡下,你会发现三件事情:

If you check the project properties, under the Build tab, you'll find three things:

在一个文本框标有条件编译符号 标记定义DEBUG常数一个复选框 在标有定义TRACE常数一个复选框

有没有这样的复选框,也常/符号pre定义具有名称释放。

There is no such checkbox, nor constant/symbol pre-defined that has the name RELEASE.

不过,你可以很容易的名称添加到文本框标记条件编译符号,但一定要设置项目配置为Release模式才这样做的,因为这些设置是每个配置。

However, you can easily add that name to the text box labelled Conditional compilation symbols, but make sure you set the project configuration to Release-mode before doing so, as these settings are per configuration.

因此​​,基本上,除非你添加文本框,#如果发布不会产生在任何配置中的任何code。

So basically, unless you add that to the text box, #if RELEASE won't produce any code under any configuration.

修改:修正的#ifdef来#IF(感谢丹尼尔)

Edit: Corrected #ifdef to #if (thanks Daniel)