Rod Rod - 1 month ago 9
C# Question

How do I set a conditional compile variable?

In C/C++ you can define macros in code like this:

#define OLD_WAY 1


Although I've never done it, I assume that the same thing is available in C#. More to the point, in C/C++ it is possible to then do some conditional compilation logic by doing something like this:

#if OLD_WAY == 1
int i = 0;
#else
int i = 1;
#endif


OK, so this is all cool and all that. And again, I assume that such logic is possible within C#. What I'd like to know is, how do I define constants at the project level, so that I can put in logic that will allow me to conditional compile one block of code if I define the constant one way, or another block of code if I don't define it that way? I'm assuming that it's done somewhere in the project's properties, but how and where do I define it?

Answer

Open your project properties and look at the Build page. There is a box called Conditional compilation symbols.

enter image description here