I know the else isn’t needed, but it’s to show the other condition too.

So, what is this magical value DEBUG? Well, it’s a preprocessor variable that is optionally added to your project at build time. By default, it’s true for Debug build, and not for Release builds. You can find it in the project settings:

You could also just put this information into the AssemblyInfo.cs file for your assembly with the same Preprocessor directives:

Here I’m using AssemblyProductto show the version as this information is shown in Details tab of the file’s properties in Windows:

Okay, so we can have the solution compile differently for Release and Debug. What if we wanted to detect it for an assembly that we’d not compiled? Well, Scott Hanselman has answered this already, but he doesn’t really define what is meant by a Debug build? Dave Black goes into this in more detail – but in short, does ‘Debug’ mean you can attach a debugger, or that optimisation of the code is turned off? I agree with his opinion – most people are asking if the code is optimized.

So, based on their offerings, here is my code for determining if an assembly was build in ‘Debug’ mode or not: