How can I easily exclude certain lines of code from a compile?

Add the attribute [Conditional("DEBUG")] onto methods you only want to have execute in your debug build. See here for more detailed information.


I would suggest enclosing your blocks in #ifdef SOMETHING and #endif, and then defining SOMETHING in your project settings when you want to include that block in your compile.


You need preprocessor directives, or conditional compile statements. You can read about them here.

An example from that link:

#define TEST
using System;
public class MyClass 
{ 
    public static void Main() 
    {
        #if (TEST)
            Console.WriteLine("TEST is defined"); 
        #else
            Console.WriteLine("TEST is not defined");
        #endif
    }
}

The code is only compiled if TEST is defined at the top of the code. A lot of developers use #define DEBUG so they can enable debugging code and remove it again just by altering that one line at the top.