First of all, create two separated solutions configurations: from within Build -> Configuration Manager select drop down Active solution configuration and select , then you can set Conditional compilation symbols in project settings for each of those configuration separately.
Then you can use Conditional
attribute on classess or methods:
[Conditional("DEBUG")]
public void Method()
{
}
Here is an example from MSDN:
#define DEBUG
using System;
using System.Diagnostics;
class Class1
{
[Conditional("DEBUG")]
public static void M() {
Console.WriteLine("Executed Class1.M");
}
}
class Class2
{
public static void Test() {
Class1.M();
}
}
This declares
Class1.M
as a conditional method.Class2
'sTest
method calls this method. Since the conditional compilation symbolDEBUG
is defined, ifClass2.Test
is called, it will callM
. If the symbolDEBUG
had not been defined, thenClass2.Test
would not callClass1.M
.