简体   繁体   English

如何在C#中定义全局预处理程序指令

[英]How to define Preprocessor Directive Global in c#

我的问题是如何在一个地方为网站中所有C#类定义全局预处理器指令。

I am able to find similar question : Preprocessor directives across different files in 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>

I don't think there is a way to create a global #define. 我认为没有办法创建全局#define。

You have to create one for each project/assembly in the solution if you need all source code files to know of that #define. 如果您需要所有源代码文件都知道该#define,则必须为解决方案中的每个项目/程序集创建一个。

This works for me in webconfig: 这在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM