![](/img/trans.png)
[英]Is it valid to use the #define preprocessor directive inside an #if in C#
[英]How to define Preprocessor Directive Global in c#
我的问题是如何在一个地方为网站中所有C#类定义全局预处理器指令。
我能够找到类似的问题: C#中跨不同文件的预处理器指令
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>TRACE;DEBUG;LINQ</DefineConstants>
</PropertyGroup>
</Project>
我认为没有办法创建全局#define。
如果您需要所有源代码文件都知道该#define,则必须为解决方案中的每个项目/程序集创建一个。
这在webconfig中对我有用:
<system.codedom>
<compilers>
<compiler
language="c#;cs;csharp" extension=".cs"
compilerOptions="/d:custompreprocessor"
type="Microsoft.CSharp.CSharpCodeProvider,
System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
</compilers>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.