Saturday, November 04, 2006

Avoid releasing ASP.NET applications with <compilation debug="true" /> using <deployment retail=”true”/>

I think most people are aware that running production ASP.NET applications with <compilation debug="true"/> is bad practice for a number of reasons but specifically because compilation takes longer due as batch optimizating is disabled and scripts and images downloaded from the WebResources.axd handler are not cached.

One of the great tricks I learnt at a Scott Guthrie session at TechEd in Sydney earlier this year, was that you can avoid the accidental deployment of applications with <compilation debug="true"/>.

Specifically, by setting the <deployment retail="true"/> switch within your machine.config file, you will disable the <compilation debug="true"/> switch, disable the ability to output trace output in a page, and turn off the ability to show detailed error messages remotely across all ASP.NET applications on the server.

<configuration>
<system.web>
<deployment retail="true/">
</system.web>
</configuration>


It's worth noting that regardless of the increased memory footprint, adding debug symbols to release assemblies can be extremely useful as it allows detailed stack trace and line error messages to be logged when exceptions occur. It's important to note that the generated pdb files must be be deployed with the assemblies for the additional debug information to be available.


To add debug symbols to a Web Deployment Project

  • open the project Property Pages
  • check the Generate debug information checkbox

Web Deployment Project - Generate Debug Symbols

To add debug information to a Web Application Project or Class Library:

  • open the project Property Pages
  • click the Build tab
  • click the Advanced button
  • select pdb-only in the Debug info dropdown
  • click the OK button

Web Application Project - Debug Info

3 comments:

Anonymous said...

Hello,

Ok, we should set 'compilation debug=”false”' before deploying the
application on the web server.
No more questions about this subject.

But now I'm confused about another aspect. I don't understand the
relationship between the 'debug' attribute and compiling the application in
'Release' mode

When doing the final build, we should compile the web application and the
web service is in "Release" mode.

However I don't understand if it's necessary to change the 'debug' attribute
to false *before compiling* in "Release" mode.

In other words, the question is this: Does the 'debug' attribute matter at
compile time or only at runtime?

Miles Ashton said...

It is my understanding that the debug attribute only matters at runtime.

Noffie said...

I agree, I think it is only at runtime that the debug attribute matters. It has to do with the part of the page that is compiled (and subsequently cached) the first time a page is requested from a freshly run web app.