Compartilhar via


How to: Create Versioned Assemblies for Precompiled Web Sites

The ASP.NET Compilation Tool (Aspnet_compiler.exe) does not create version numbers automatically each time you build a Web site. Instead, you must set the version number by specifying assembly attributes in a separate file. You then use either the compilerOptions attribute of the compiler Element for compilers for compilation (ASP.NET Settings Schema) in your Web.config file or the CompilerOptions attribute of the @ Page directive in your .aspx page.

This procedure uses an assembly-information file to set the version number for the Web site, and it demonstrates how to include the assembly information file from both the Web.config file and an .aspx page.

For more information about precompilation, see ASP.NET Web Site Precompilation.

To create an assembly-information file for your application

  1. Using a text editor, create a new assembly-information file. For Visual Basic applications, the suggested file name is AssemblyInfo.vb. For C# applications, the suggested file name is AssemblyInfo.cs.

  2. Add the following code to the assembly-information file.

    <assembly:System.Reflection.AssemblyVersionAttribute("versionNumber")>
    
    [assembly:System.Reflection.AssemblyVersionAttribute("versionNumber")]
    

    For information about the format of the versionNumber parameter, see the AssemblyVersionAttribute class.

    NoteNote

    Do not place the assembly-information file in the App_Code directory. If you place the assembly-information file in the App_Code directory, it will be compiled automatically by the ASP.NET runtime and might cause compilation errors later in the compilation process.

To specify the assembly-information file in your .aspx page

  1. Open your .aspx file in a text editor.

  2. Add the following attribute to the @ Page directive in the .aspx page.

    CompilerOptions="path\AssemblyInfo.vb"
    
    CompilerOptions="path\AssemblyInfo.cs"
    

    Replace the path parameter with the physical path to the assembly-information file on disk.

    If the path to your assembly-information file contains spaces, you must enclose the path and file name in single quotation marks (').

    CompilerOptions='"path with spaces\AssemblyInfo.vb"'
    
    CompilerOptions='"path with spaces\AssemblyInfo.cs"'
    

    Replace the path with spaces parameter with the physical path to the assembly-information file on disk.

  3. Compile your application for deployment. For more information, see How to: Precompile ASP.NET Web Sites for Deployment.

To specify the assembly-information file in your Web.config file

  1. Open your Web.config file in a text editor.

  2. Add the following code to your Web.config file.

    <system.codedom>
      <compilers>
        <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" 
          type="Microsoft.VisualBasic.VBCodeProvider, System, 
          Version=2.0.3600.0, Culture=neutral, 
          PublicKeyToken=b77a5c561934e089" 
          compilerOptions="path\AssemblyInfo.vb" />
      </compilers>
    </system.codedom>
    
    <system.codedom>
      <compilers>
        <compiler language="c#;cs;csharp" extension=".cs"
          type="Microsoft.CSharp.CSharpCodeProvider, System,
          Version=2.0.3600.0, Culture=neutral, 
          PublicKeyToken=b77a5c561934e089" warningLevel="1" 
          compilerOptions="path\AssemblyInfo.cs" />
      </compilers>
    </system.codedom>
    
  3. Compile your application for deployment. For more information, see How to: Precompile ASP.NET Web Sites for Deployment.

See Also

Tasks

How to: Precompile ASP.NET Web Sites

Other Resources

ASP.NET Web Site Precompilation