Compiling and Publishing Web Sites

Posted Wednesday, October 19, 2005 8:26 AM by C-Dog's .NET Tip of the Day
Compilation and Publishing in ASP.NET 2.0 is completely different than in ASP.NET 1.1.  In ASP.NET 1.1, whether you debugged the code or ran it from a server, all of the .cs files were compiled into a single dll (i.e.: thrifty.web.dll) and the markup (.aspx and .ascx) remained seperate.  This could often lead to problems if you declared a control in the markup but then didn't have a coresponding reference in the .cs file.  All of this has changed.
 
First and foremost, when you click Build Web Site, it does not compile all of the .cs files into a single dll.  It only validates that the code is syntactically correct.  It will validate the .cs files as well as the .aspx and .ascx files.  When you run it through the debugger or you use xcopy deployment directly against the files in your web project, it uses dynamic compilation to run the web site.  This means that if you change a .cs file, the next time that file is hit in a web browser, it will compile it on the fly.  This can be cool for some for development, but not ideal for deployment.
 
So when you want to deploy the web site, you click Publish Web Site.  You can also do this using the new aspnet_compiler.exe and point it to a solution file (allowing for automated builds, etc.).  The Publish Web Site dialog will prompt you for a location.  This can be a file path, a web site address, or ftp site.  It also has three different options:
 
  • Allow this precompiled site to be updatable
  • Use fixed naming and single page assemblies
  • Enable strong naming on precompiled assemblies

The Allow this precompiled site to be update option when checked leaves all of the .aspx and .ascx files alone.  This way they can be changed by an external tool (i.e.: Rhythmyx).  When it is unchecked, it compiles the entire site including .aspx and .ascx files into a single dll or multiple dlls.

The Use fixed naming and single page assemblies option tells the compiler to use the same names for the dlls it creates every time it compiles.  It also will make the compiler create seperate dlls for every page and control on the site.  This will allow for indiviudal controls to be updated without affecting any of the other ones.  The filename format for a particular dll will be App_web_<filename>.<random four byte hex string>.dll.  So the filename for the LocationTime control would look like this, App_web_locationtime.ascx.2ce845ef.dll.  The random four byte hex string is supposedly the same every time you compile.  It also seems to use the same string at each directory level.  When unchecked there is no guarantee what the filenames will be in the dlls and entire directories will be grouped into the same dlls.

Enable Strong Naming on Precompiled Assemblies is basically the same as specifynig a key in the assemblyinfo.cs in ASP.NET 1.1.

As described above, there are a ton of differences in compiling with ASP.NET 2.0.  Hopefully this will make it easier to understand.

Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=39