Asp.net release build vs debug build

HttpContext.IsDebuggingEnabled


If you want to know if the dll was built in Debug mode, with the debug attributes, then your best bet is reflection.

Taken from "How to tell if an existing assembly is debug or release":

Assembly assembly = Assembly.GetAssembly(GetType());
bool debug = false;
foreach (var attribute in assembly.GetCustomAttributes(false)){
  if (attribute.GetType() ==  typeof(System.Diagnostics.DebuggableAttribute)){
    if (((System.Diagnostics.DebuggableAttribute)attribute)
        .IsJITTrackingEnabled){
      debug = true;
      break;
    }
  }
}

This will get the assembly that is calling that code (in effect itself), and then set the debug boolean to true if the assembly was compiled in debug mode, otherwise it's false.

This could easily be dropped into a console app (as in the linked example), and then you pass in the path of the dll/exe you want to check. You would load the assembly from a path like this:

Assembly assembly = 
    Assembly.LoadFile(System.IO.Path.GetFullPath(m_DllPath.Text));

For one in Web.config debug will be set to true, however you can actually set this in a release application too.

In debug however defines like DEBUG are set, so it's simple to do:

bool is_debug;

#ifdef DEBUG
is_debug = true;
#else
is_debug = false;
#endif