#如果preprocessor指令,指令比DEBUG等

编程入门 行业动态 更新时间:2024-10-27 13:23:22
本文介绍了#如果preprocessor指令,指令比DEBUG等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道,我可以使用preprocessor指令来检查调试/发布这样做的:

#如果DEBUG     //调试模式 #elif指令     //释放模式 #ENDIF

但如何检查其他配置,如测试。在VB中,你可以这样做:

#如果CONFIG =释放然后     发行模式 #ElseIf CONFIG =测试然后,     '测试模式 #ElseIf CONFIG =调试然后,     '调试模式 #END如果

所以,我的问题是,在C#中,我怎么能检查测试模式?我有,我想,如果我在调试和测试执行一些code,但不是在释放模式,所以具体而言,我需要一种方法来为您在发布模式不是。在VB中,我会做这样的:

#如果没有CONFIG =释放然后     做的东西在这里为每一个未发布的配置 #END如果

解决方案

这是一样的调试。对于code,你只需要在测试生成配置运行:

#如果测试 // ... #ENDIF

和为code,你不希望在测试版本的配置中运行,您可以的#else 以上,或做到这一点:

#如果!TEST // ... #ENDIF

这一切都假定您已经定义了一个构建配置,列出测试中的条件编译符号文本框中(在项目属性>构建选项卡,这是一个空间分隔的列表)。

I know that I can use preprocessor directives to check for Debug/Release by doing this:

#if DEBUG //debug mode #elif //release mode #endif

but what about checking for other configurations, like Test. In VB you can do this:

#If CONFIG = "Release" Then 'Release mode #ElseIf CONFIG = "Test" Then 'Test mode #ElseIf CONFIG = "Debug" Then 'Debug mode #End If

So, my question is in C#, how can I check for Test mode? I have some code that I want to execute if I'm in Debug AND Test, but not in Release mode, so specifically, I need a way to check for not being in Release mode. In VB I would do this:

#If Not CONFIG = "Release" Then 'Do something here for every configuration that is not Release #End If

解决方案

It's the same as for DEBUG. For code that you only want to run in the TEST build configuration:

#if TEST // ... #endif

And for code you don't want to run in the TEST build configuration, you can either #else the above, or do this:

#if !TEST // ... #endif

This all assumes that you've defined a build configuration that lists TEST in the "Conditional compilation symbols" text box (under project properties > Build tab; this is a space-delimited list).

更多推荐

#如果preprocessor指令,指令比DEBUG等

本文发布于:2023-11-13 11:54:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584290.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指令   preprocessor   DEBUG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!