Running different code in visual studio debugging and release settings

Is it possible for C # to execute certain line codes in the debug settings, and others in the release settings.

if #debug

//run some lines of code

else 

// run different lines of code
+5
source share
2 answers

You can do something like:

#if DEBUG
// Debug Code

#else
// Release Code

#endif

I use this in WCF services to run it as a console application when debugging, but as a Windows service in the release

NTN, Rupert.

+7
source

Read this blog post If youre using "#if DEBUG", Youre Doing It Wrong , the author suggests using System.Diagnostics.ConditionalAttribute:

[Conditional("DEBUG")]
private static void DebugMethod()
{
    // Debugging code
}
+3
source

All Articles