简体   繁体   English

C#是否允许针对不同解决方案的预处理器指令

[英]Does C# allow Preprocessor Directive for different Solutions

We have Preprocessor Directives in Visual Studio for c#, for example: 我们在Visual Studio中为c#提供了预处理器指令,例如:

#define CONDITION1

#if CONDITION1
    Console.WriteLine("Version1");
#else
    Console.WriteLine("Version2");
#endif

But what should I do if I have a library and want it to compile differently to different solution? 但是,如果我有一个库并希望将其编译为不同的解决方案,该怎么办?

For example, I want to #define CONDITION1 in solution1, and #define CONDITION2 in solution2, what should I do? 例如,我想在解决方案1中#define CONDITION1,在解决方案2中#define CONDITION2,该怎么办?

Unless you're distributing the raw C# project to be included in several solutions, you're out of luck. 除非您要分发原始的C#项目以将其包含在多个解决方案中,否则您很不幸。 If you're going that route, you'd use them the same as any other #define . 如果您要沿着那条路线走,则可以将它们与其他任何#define一样使用。

Most libraries are distributed as pre-compiled source which means that all of the #define s would've been handled already. 大多数库都是作为预编译的源分发的,这意味着所有#define都已被处理。 You'd have to fall back to configuration values (which is exactly how behaviors like this should be handled). 您必须退回到配置值(这正是应该如何处理此类行为)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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