Precompilation In ASP.NET 2.0

Before publishing an ASP.Net(C#, VB.Net) project, there are certain prerequisites that have to be in place. An ASP.Net(C#, VB.Net) project is compiled as part of the publishing process and this requires the existence of the .Net Framework SDK version 1.0.3705 or later. One of the files included in the .Net Framework SDK is the C# or VB.Net compiler. CodeCharge Studio needs to know the path to this file since it will be used to compile and build a .dll file when the project is published.

The C# compiler is a file called csc.exe while the VB.Net compiler is called vbc.exe. The path to this file depends on the location where the SDK is installed. An example path would be C:\WINNT\Microsoft.NET\Framework\v1.0.3705. Within CodeCharge Studio, open the Tools --> Options… menu and in the Options window, click on the Paths option. In the field entitled .Net SDK, enter the path to the C# or VB.Net compiler file.
ASP.NET dynamically parses and compiles all the ASPX pages in a folder when the first request arrives for a page inside that folder. ASP.NET also needs to compile applicable files in the special folders, like App_Code, on the first request, and any code-behind files associated with ASPX and ASCX files. The runtime caches all the compilation results in order to quickly process later requests, and does not need to recompile again unless someone edits a file. This behavior gives us a great deal of flexibility, including the flexibility to change code and markup and instantly have the changes reflected in the next browser request.

The price for this flexibility is the performance hit on the first request. Some people have found their ASP.NET applications to be slow starters. These people usually work in the sales department and perform software demos in front of customers. In place pre-compilation makes the “first hit” to a web application and forces all pages and code in the application to compile.

The tool to use for pre-compilation is the aspnet_compiler executable, which you can find in the %WINDIR%\Microsoft.NET\Framework\v2.x.xxxx directory. If we have a web application in the WebSite1 virtual directory under IIS, we could use the following command line to compile the application.

The –v parameter specifies that we are passing a virtual path to our web site. On servers with multiple websites you may need to use the –m parameter and specify the full IIS metabase path to the application (-m /LM/W3SVC/1/Root/WebSite1).

The pre-compiled code will end up inside of the Temporary ASP.NET File directory, just as it would when the runtime compiles files for a browser request. Inside of the bin directory for the compiled site, you’ll find the assemblies (dll files). The compiler generates special filenames to avoid naming collisions. In the shot below, the dll starting with App_Code contains the code from the App_Code directory – not too surprising. Each folder containing aspx, or ascx files will compile into a dll prefixed with App_Web. The files with a .compiled extension contain XML with information about which original source code file maps to which assembly.

With the compiled files in place your web application should have a slightly better startup time, but a primary benefit to in place pre-compilation will be the ability to ensure the web application is error free. If you happen to modify a class or web form and leave an error in the file, the aspnet_compiler will fail and display the compiler error. The tool will also display any warnings, but warning will not stop compilation.
Tags: , , , ,
Hot on Web:


About author