The ASP.NET Compilation tool can be used in two general ways: for in-place compilation and compilation for deployment, where a target output directory is specified. The following sections describe these scenarios.
Compiling an Application in Place
The ASP.NET Compilation tool can compile an application in place, that is, it mimics the behavior of making multiple requests to the application, thus causing regular compilation. Users of a precompiled site will not experience a delay caused by compiling the page on first request.
Note that if you are using an impersonated account, both the account and the logon user account must have write access to the target for precompilation to succeed.
When you precompile a site in place, the following items apply:
The site retains its files and directory structure.
You must have compilers for all programming languages used by the site on the server.
If any file fails compilation, the entire site fails compilation.
You can also recompile an application in place after adding new source files to it. The tool compiles only the new or changed files unless you include the -c option.
Note: |
|---|
Compilation of an application that contains a nested application does not compile the nested application. The nested application must be compiled separately.
|
Note: |
|---|
When you compile a Web application that includes master pages, compilation can fail if you compile the application as an updatable site and a naming conflict occurs. The conflict can occur if the name of the master page matches the name of the namespace for a content page that derives from the master page. (The inheritance relationship is established by the
Inherits attribute of the @ Page directive). To work around this issue, you can either change the class name of the master page or change the namespace name, or you can compile the application as non-updatable.
|
Compiling an Application for Deployment
You compile an application for deployment (compilation to a target location) by specifying the targetDir parameter. The targetDir can be the final location for the Web application, or the compiled application can be further deployed.
Using the -u option compiles the application in such a way that you can make changes to certain files in the compiled application without recompiling it. Aspnet_compiler.exe makes a distinction between static and dynamic file types, and handles them differently when creating the resulting application.
Static file types are those that do not have an associated compiler or build provider, such as files whose names have extensions such as .css, .gif, .htm, .html, .jpg, .js and so on. These files are simply copied to the target location, with their relative places in the directory structure preserved.
Dynamic file types are those that have an associated compiler or build provider, including files with ASP.NET-specific file name extensions such as .asax, .ascx, .ashx, .aspx, .browser, .master, and so on. The ASP.NET Compilation tool generates assemblies from these files. If the -u option is omitted, the tool also creates files with the file name extension .COMPILED that map the original source files to their assembly. To ensure that the directory structure of the application source is preserved, the tool generates placeholder files in the corresponding locations in the target application.
You must use the -u option to indicate that the content of the compiled application can be modified. Otherwise, subsequent modifications are ignored or cause run-time errors.
The following table describes how the ASP.NET Compilation tool handles different file types when the -u option is included.
File type
|
Compiler action
|
|---|
.ascx, .aspx, .master
|
These files are split into markup and source code, which includes code-behind files. Source code is compiled into assemblies, with names that are derived from a hashing algorithm, and the assemblies are placed in the Bin directory. Any inline code, that is, code enclosed in <script runat="server"> elements, is included with markup and not compiled. New files with the same name as the source files are created to contain the markup and placed in the corresponding output directories.
|
.ashx, .asmx
|
These files are not compiled and are moved to the output directories as is and not compiled. If you wish to have the handler code compiled, place the code into source code files in the App_Code directory.
|
.cs, .vb, .jsl, .cpp
(not including code-behind files for the file types listed earlier)
|
These files are compiled and included as a resource in assemblies that reference them. Source files are not copied to the output directory. If a code file is not referenced, it is not compiled.
|
Custom file types
|
These files are not compiled. These files are copied to the corresponding output directories.
|
Source code files in the App_Code subdirectory
|
These files are compiled into assemblies and placed in the Bin directory.
Note: |
|---|
Static file types in the App_Code directory are not copied to the output directories.
|
|
.resx and .resource files in the App_GlobalResources subdirectory
|
These files are compiled into assemblies and placed in the Bin directory. No App_GlobalResources subdirectory is created under the main output directory, and no .resx or .resources files located in the source directory are copied to the output directories.
Note: |
|---|
The resource files in the App_GlobalResources subdirectory are compiled into assemblies before code in the App_Code subdirectory is compiled. Modification of resource files after compilation is not supported.
|
|
.resx and .resource files in the App_LocalResources subdirectory
|
These files are not compiled and are copied to the corresponding output directories.
|
.skin files in the App_Themes subdirectory
|
The .skin files and static theme files are not compiled and are copied to the corresponding output directories.
|
.browser
Web.config
Static file types
Assemblies already present in the Bin directory
|
These files are copied as is to the output directories.
|
The following table describes how the ASP.NET Compilation tool handles different file types when the -u option is omitted.
Note: |
|---|
No warnings are provided to prevent you from modifying the source code of a compiled application.
|
File type
|
Compiler action
|
|---|
.aspx, .asmx, .ashx, .master
|
These files are split into markup and source code, which includes both code-behind files and any code that is enclosed in <script runat="server"> elements. Source code is compiled into assemblies, with names that are derived from a hashing algorithm. The resulting assemblies are placed in the Bin directory. Any inline code, that is, code enclosed between the <% and %> brackets, is included with markup and not compiled. The compiler creates new files to contain the markup with the same name as the source files. These resulting files are placed in the Bin directory. The compiler also creates files with the same name as the source files but with the extension .COMPILED that contain mapping information. The .COMPILED files are placed in the output directories corresponding to the original location of the source files.
|
.ascx
|
These files are split into markup and source code. Source code is compiled into assemblies and placed in the Bin directory, with names that are derived from a hashing algorithm. No markup files are generated.
|
.cs, .vb, .jsl, .cpp
(not including code-behind files for the file types listed earlier)
|
Source code that is referenced by the assemblies generated from .ascx, .ashx, or .aspx files is compiled into assemblies and placed in the Bin directory. No source files are copied.
|
Custom file types
|
These files are compiled like dynamic files. Depending on the type of file they are based on, the compiler can place mapping files in the output directories.
|
Files in the App_Code subdirectory
|
Source code files in this subdirectory are compiled into assemblies and placed in the Bin directory.
Note: |
|---|
Static file types in the App_Code directory are not copied to the output directories.
|
|
Files in the App_GlobalResources subdirectory
|
These files are compiled into assemblies and placed in the Bin directory. No App_GlobalResources subdirectory is created under the main output directory. If the configuration file specifies appliesTo="All", .resx and .resources files are copied to the output directories. They are not copied if they are referenced by a BuildProvider.
|
.resx and .resource files in the App_LocalResources subdirectory
|
These files are compiled into assemblies with unique names and placed in the Bin directory. No .resx or .resource files are copied to the output directories.
|
.skin files in the App_Themes subdirectory
|
Themes are compiled into assemblies and placed in the Bin directory. Stub files are created for .skin files and placed in the corresponding output directory. Static files (such as .css) are copied to the output directories.
|
.browser
Web.config
Static file types
Assemblies already present in the Bin directory
|
These files are copied as is to the output directory.
|
Fixed Assembly Names
Some scenarios, such as deploying a Web application using the MSI Windows Installer, require the use of consistent file names and contents, as well as consistent directory structures to identify assemblies or configuration settings for updates. In those cases, you can use the -fixednames option to specify that the ASP.NET Compilation tool should compile an assembly for each source file instead of using the where multiple pages are compiled into assemblies. This can lead to a large number of assemblies, so if you are concerned with scalability you should use this option with caution.
Strong-Name Compilation
Associated ASP.NET Classes