[英]How to replace Preprocessor directives with C# code,Alternative for preprocessor directives
[英]Can preprocessor directives be used outside of code files?
我知道如何在代码文件中使用它们,这是MSDN-Pages中的示例:
// preprocessor_if.cs
#define DEBUG
#define MYTEST
using System;
public class MyClass
{
static void Main()
{
#if (DEBUG && !MYTEST)
Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
Console.WriteLine("DEBUG and MYTEST are defined");
#else
Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
}
}
是否可以在XML(或其他非代码)文件中使用#if
来调试和发布不同的数据? 例如:
<coustomXml>
#if DEBUG
<item>debugdata</item>
#else
<item>releaseData</item>
#endif
</coustomXml>
我用我的项目的app.config尝试了这个,但是编译器忽略了这些标志。
使用编译器指令是不可能的,但您可以根据构建类型使用config transofrmations:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.