HOW TO:建立先行編譯網站的建立版本組件

更新:2007 年 11 月

ASP.NET 編譯工具 (Aspnet_compiler.exe) 不會自動在您每次建置網站時建立版本號碼。所以,您必須在個別的檔案中指定組件 (Assembly) 屬性 (Attribute),藉以設定版本號碼。然後,您就可以在 Web.config 檔中使用 編譯之編譯器的 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 類別。

    注意事項:

    請勿將組件資訊檔放置於 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. 編譯應用程式以便部署。如需詳細資訊,請參閱 HOW TO:先行編譯 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. 編譯應用程式以便部署。如需詳細資訊,請參閱 HOW TO:先行編譯 ASP.NET 網站以便部署

請參閱

工作

HOW TO:先行編譯 ASP.NET 網站

其他資源

ASP.NET 網站先行編譯