Share via


如何:为预编译网站创建带有版本的程序集

更新:2007 年 11 月

ASP.NET 编译工具 (Aspnet_compiler.exe) 不会在每次生成网站时自动创建版本号。相反,必须通过在单独的文件中指定程序集属性来设置版本号。然后在 Web.config 文件中使用 compilation 的 compilers 的 compiler 元素(ASP.NET 设置架构) 的 compilerOptions 属性,或在 .aspx 页中使用 @ Page 指令的 CompilerOptions 属性。

此过程使用程序集信息文件设置网站的版本号,并演示如何从 Web.config 文件和 .aspx 页中包含程序集信息文件。

有关预编译的更多信息,请参见 ASP.NET 网站预编译

为应用程序创建程序集信息文件

  1. 使用文本编辑器创建一个新的程序集信息文件。对于 Visual Basic 应用程序,建议的文件名为 AssemblyInfo.vb。对于 C# 应用程序,建议的文件名为 AssemblyInfo.cs。

  2. 将下列代码添加到程序集信息文件。

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

    有关 versionNumber 参数的格式的信息,请参见 AssemblyVersionAttribute 类。

    ms228042.alert_note(zh-cn,VS.90).gif说明:

    不要将程序集信息文件放在 App_Code 目录中。如果将程序集信息文件放在 App_Code 目录中,ASP.NET 运行库将自动编译它,并且可能在以后的编译过程中导致编译错误。

在 .aspx 页中指定程序集信息文件

  1. 在文本编辑器中打开 .aspx 文件。

  2. 将以下属性添加到 .aspx 页中的 @ Page 指令。

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

    将 path 参数替换为程序集信息文件在磁盘上的物理路径。

    如果程序集信息文件的路径包含空格,则必须用单引号 (') 将路径和文件名括起。

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

    将 path with spaces 参数替换为程序集信息文件在磁盘上的物理路径。

  3. 编译应用程序以进行部署。有关更多信息,请参见如何:预编译 ASP.NET 网站以进行部署

在 Web.config 文件中指定程序集信息文件

  1. 在文本编辑器中打开 Web.config 文件。

  2. 向 Web.config 文件添加下面的代码。

    <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. 编译应用程序以进行部署。有关更多信息,请参见如何:预编译 ASP.NET 网站以进行部署

请参见

任务

如何:预编译 ASP.NET 网站

其他资源

ASP.NET 网站预编译