How to check if an assembly was built using Debug or Release configuration?

born to hula picture born to hula · Feb 2, 2010 · Viewed 23.5k times · Source

I'm starting deployment of my web application and I need to guarantee that all the assemblies that are going to be deployed were built using Release configuration. Our system was developed using C#/.Net 3.5.

Is there any way to achieve this?

Answer

David picture David · Feb 2, 2010

Check this. The idea is that you get the list of assembly attributes using Assembly.GetCustomAttributes() and search for DebuggableAttribute and then find if such attribute has IsJITTrackingEnabled property set.

    public bool IsAssemblyDebugBuild(Assembly assembly)
    {
        return assembly.GetCustomAttributes(false).OfType<DebuggableAttribute>().Any(da => da.IsJITTrackingEnabled);
    }