How to mark a part of c# code to be compiled if particular library is referenced and ignored if it isn't?

I would like to build a version of an application of mine without use of some features provided by a class library but avoid deleting the actual code (the code using the feature and the corresponding using directive).

Normally the whole application is going to fail to be built as soon as I unreference the assembly but I would like the dependent code parts to be excluded from compilation process instead.

Is this possible?

Jon Skeet
people
quotationmark

You can use preprocessor directives to control this - not on the basis of your references, but on the basis of symbols:

#if USE_SOME_LIBRARY
   // Code that uses the library
#endif

Then just make sure that you define USE_SOME_LIBRARY in any build configurations where you have the reference.

people

See more on this question at Stackoverflow