ASP.NET: How to deploy website with precompile

Resources:

Precompile your website and publish it without source code or markup

by: Ted Nyberg (Ted & Gustaf)

IMPORTANT: This approach won’t work with EPiServer CMS 5 unless you implement this experimental workaround

EPiServer CMS 5 uses virtual path providers which aren’t supported by the .NET framework for precompiled websites. This workaround is used to circumvent the default .NET behavior for registering virtual path providers.

Brief introduction to building versus precompiling

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!

Precompile your web application before deployment

When you precompile your web application the following takes place:
  • All markup files (.aspx) are stripped of their content
  • All web service files (.asmx) are stripped of their content
  • All code-behind files (.cs) are removed
  • 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 precompile your website

In order to precompile your web application you need to use a simplecommand prompt command. If you wanted you could add this command to a post-build event to automate the process.
The precompilation 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 
-p: physical path of the application to be compiled
-v: virtual path of the application to be compiled
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:

02 September 2008


Comments

  1. aspnet_compiler -p C:\MyWebsite -v / C:\MyPrecompiledWebsite After applying the above command ( by replacing my site path) the target folder become empty. While it is precompiliting I could able to see the bin folder and some …..complied names. I check the messages as it showed while processing, there are no “Error” only warnings exist. What could be the cause?
  2. First you should make absolutely sure that there are no errors in the output. If the output only contains warnings you should be able to see at least some files in the target folder. Also, you can try using the “Publish Web Site” command from within Visual Studio to see if that makes any difference. What version of ASP.NET are you using?
  3. Thanks for this post.. it helped me a lot.
  4. good Post.!!! HAT OFF

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s