How to determine if a running ASP.NET App was compiled in Debug or Release Mode?

Recently there was a dotnet.framework.aspnet newsgroup post on this subject. I answered it, but my answer wasn't complete. Here is a short example of how you can definitively tell - AT RUNTIME - if the assembly was built in Debug or Release mode:


// in AssemblyInfo.cs:
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

private string buildMode=String.Empty;
private void Page_Load(object sender, System.EventArgs e)
{
Assembly asm = Assembly.GetExecutingAssembly();
object[] objArray=asm.GetCustomAttributes(false) ;
foreach (object obj in objArray)
{
AssemblyConfigurationAttribute conf =
obj as AssemblyConfigurationAttribute;
if (conf != null)
this.buildMode=conf.Configuration ;
}
Response.Write("Build Mode: " +this.buildMode);
}


On a lighter note, you just gotta weep to see this on Microsoft's security pages :
A Parent's Primer to Computer Slang.



--- w00t?

Comments

Popular posts from this blog

Some observations on Script Callbacks, "AJAX", "ATLAS" "AHAB" and where it's all going.

IE7 - Vista: "Internet Explorer has stopped Working"

FIREFOX / IE Word-Wrap, Word-Break, TABLES FIX