将#if RELEASE工作像#if DEBUG在C#中? [英] Will #if RELEASE work like #if DEBUG does in C#?

查看:1402
本文介绍了将#if RELEASE工作像#if DEBUG在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看过的#if编译指令的所有例子中,他们使用DEBUG。我可以使用RELEASE以同样的方式排除我不想运行时编译在调试模式下的代码?

解决方案

div>

不,它不会,除非你做一些工作。



这里的重要部分是什么DEBUG真的是,它是一种常量定义



如果你检查项目属性,在Build选项卡下,你会发现三件事:




  • 标有条件编译符号的文本框

  • 标记为定义DEBUG常数的复选框

  • 标有定义TRACE常数的复选框



没有这样的复选框,名称为RELEASE。



但是,您可以轻松地将该名称添加到标记为条件编译符号的文本框,但确保在进行之前将项目配置设置为发布模式



所以基本上,除非你添加到文本框, #if RELEASE :已更正#ifdef 到#if(感谢Daniel)


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.

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:

  • A text box labelled "Conditional compilation symbols"
  • A check box labelled "Define DEBUG constant"
  • A check box labelled "Define TRACE constant"

There is no such checkbox, nor constant/symbol pre-defined that has the name 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.

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


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

这篇关于将#if RELEASE工作像#if DEBUG在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆