0

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

#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?

ncite
  • 533
  • 1
  • 4
  • 19
  • 1
    Maybe [this post](http://stackoverflow.com/questions/2355340/how-do-i-define-a-preprocessor-symbols-in-c-sharp-visual-studios) is an option. At the project level (not solution level) you can define a symbol, then you can check if that symbol is there to know which project you are in. – Quantic Sep 20 '16 at 19:09

1 Answers1

0

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).

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536