我知道,我可以使用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 #endifbut 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 IfSo, 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 // ... #endifAnd for code you don't want to run in the TEST build configuration, you can either #else the above, or do this:
#if !TEST // ... #endifThis 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等
发布评论