ncite ncite - 3 months ago 16
C# Question

Does C# allow Preprocessor Directive for different Solutions

We have Preprocessor Directives in Visual Studio for c#, for example:

#define CONDITION1


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?


Unless you're distributing the raw C# project to be included in several solutions, you're out of luck. If you're going that route, you'd use them the same as any other #define.

Most libraries are distributed as pre-compiled source which means that all of the #defines would've been handled already. You'd have to fall back to configuration values (which is exactly how behaviors like this should be handled).