Search code examples
c#conditional-compilation

Compile lines, only if in Development Environment?


I need some lines of code to only be compiled in Development Environment. They assist in development, and there is quite a few, so manually removing them is not an option.

If have looked into Conditional Compiling and it seems like #if would be a good solution. I am new to the concept and can't seem to figure out how to check the current environment. I know how to do it outside of the #if but access is severely limited inside of it.

As an example:

#if (Condition)
    Console.WriteLine("Hello World!")
#endif

I want this line to only compile if I am in a Development Environment.


Solution

  • This should work:

    #if (DEBUG)
        Console.WriteLine("Hello World!")
    #endif