Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Visual Studio 2008 capable of conditional compilation for C#?

Referring to the "Configuration Manager" under the Build menu,

Is there a way to comment my C# code so that the commented out code does not compile while the solution is in Debug mode, but would compile if I changed it to Release mode?

Why do I want this? The reason that I want to have code that will be compiled in Release mode, but not in Debug, is that I've got some code that will not work from my development PC (code that sends emails from my host, etc.).

Instead of having to run back through my code and uncomment lines before publishing, I'd like that to be automatic.

like image 267
Chaddeus Avatar asked Jul 11 '09 12:07

Chaddeus


1 Answers

You may be looking for something like this:

#if DEBUG
     Console.WriteLine("Debug Mode");
#else
     Console.WriteLine("Release Mode");
#endif

If you only care about release mode, you can use:

#if !DEBUG
     Console.WriteLine("Release Mode");
#endif
like image 78
BlueMonkMN Avatar answered Oct 16 '22 14:10

BlueMonkMN