- Brief introduction to building versus pre compiling
If you build your web application in Visual Studio you'll get at least a few binaries, or .dll, files in your bin folder. However, there is more compiling to be done. Normally this would happen when an ASP.NET resource within the web site is requested for the first time after restart. Unless you deploy your web application in a precompiled state that is! - Pre compile your web application before deployment
When you precompile your web application the following takes place:
1. All markup files (.aspx) are stripped of their content
2. All web service files (.asmx) are stripped of their content
3. All code-behind files (.cs) are removed
4. All user control files (.ascx) are removed
...and some other things
This means that you will be able to deploy your website entirely without readable markup or source code.
You still need all the markup files in the correct places, but they will no longer contain any actual markup. So, in the future you won't have to worry about updating .aspx files - unless new ones have been added to the web application. - How to pre compile your website
In order to pre compile your web application you need to use a simple command prompt command. If you wanted you could add this command to a post-build event to automate the process.
The pre compilation is carried out by the aspnet_compiler executable located in your .NET installation folder. If you run the Visual Studio command prompt you won't have to worry about that though - the path variable is then set so that you can execute the aspnet_compiler executable regardless of what folder you are in.
If you use the standard command prompt (cmd) you'll have to switch to the correct .NET installation folder, for example:
> c: > cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
So, let's say I have a website located in C:\MyWebSite. In order to precompile this website I use aspnet_compiler and specify a target folder for the precompiled output:
> aspnet_compiler -p C:\MyWebsite -v / C:\MyPrecompiledWebsite
The C:\MyPrecompiledWebsite will now contain a precompiled version of the web application. All markup and web service files will now be empty except for a text saying (my emphasis): "This is a marker file generated by the precompilation tool, and should not be deleted!"
You are now ready to deploy! - Additional information
For more information on different precompilation scenarios and techniques, see:
ASP.NET Precompilation Overview
How to: Precompile ASP.NET Web Sites
How to: Precompile ASP.NET Web Sites for Deployment
Please make a note that this type of deployments are really impressive in scenarios where the site is finally ready to move on your production environment and the modifications are not so frequent on you web site. Also, another case may be if you don't really want to give your code to the client ;).