compilation 項目 (ASP.NET 設定結構描述)

設定 ASP.NET 用來編譯應用程式的所有編譯設定。

<compilation 
   debug="[true|false]"
   batch="[true|false]"
   batchTimeout="number of seconds"
   defaultLanguage="language" 
   explicit="[true|false]" 
   maxBatchSize="maximim number of pages"
   maxBatchGeneratedFileSize="maximum combined size"
   numRecompilesBeforeAppRestart="number"
   strict="[true|false]" 
   tempDirectory="temporary files directory"
   urlLinePragmas="[true|false]"
   optimizeCompilations="[true|false]"
   targetFramework="2.0|3.0|3.5|4.0"
   assemblyPostProcessorType="assembly post processor, assembly"
>
   <assemblies>...</assemblies> 
   <buildProviders>...</buildProviders>
   <folderLevelBuildProviders>...</folderLevelBuildProviders>
   <codeSubDirectories>...</codeSubDirectories>
   <compilers>...</compilers>
   <expressionBuilders>...</expressionBuilders>
</compilation>

屬性和項目

下列章節會說明屬性、子項目和父項目。

屬性

屬性

描述

assemblyPostProcessorType

選擇性 String 屬性。

指定組件的後續處理編譯步驟,方法是參考組件後續處理器。 使用格式 "assembly post processor, assembly"。 assembly post processor 必須實作 IAssemblyPostProcessor 介面。 使用後續處理的這個方法會在編譯時強制偵錯,指定部署模式時可以覆寫這個方法。

這個屬性是 .NET Framework 2.0 版中新增的屬性。

預設為空字串。

batch

選擇性 Boolean 屬性。

指示是否支援批次處理。

如果為 True,則會排除在首次存取檔案時,由必要編譯所造成的延遲。 當這個屬性設定為 True 時,ASP.NET 便會以批次模式先行編譯所有未編譯的檔案,進而在首次編譯這些檔案時造成甚至更久的延遲。 然而,經過這次初始的延遲之後,即可在後續存取檔案時排除編譯延遲。

預設為 True。

batchTimeout

選擇性 TimeSpan 屬性。

指定批次編譯的逾時期間 (以秒為單位)。 如果無法在逾時週期內完成編譯,編譯器會還原成目前網頁的單一編譯模式。

預設為 "900" (15 分鐘)。

debug

選擇性 Boolean 屬性。

指定是否要編譯偵錯二進位碼檔案而非正式版本的二進位碼檔案。

預設值為 False。

defaultLanguage

選擇性 String 屬性。

指定用於動態編譯檔案中的預設程式語言,例如 "C#" 或 "PERL"。 使用 system.codeDom 區段的 compilers 項目,或是這個項目 (已取代) 的 compilers 子項目,即可定義語言名稱。

預設值為 "vb"。

explicit

選擇性 Boolean 屬性。

指定是否設定 Microsoft Visual Basic explicit 編譯選項。 如果為 True,就必須使用 Dim、Private、Public 或 ReDim 陳述式來宣告所有的變數。

預設為 True。

maxBatchGeneratedFileSize

選擇性 Int32 屬性。

指定每一批次處理之編譯所產生的原始程式檔的最大組合大小 (以 KB 為單位)。 一般而言,當實際上只需要較少位元時,最好不要將大型組件載入至記憶體中。 這項限制有助於讓組件的大小位於合理的範圍之內,如此應用程式即可善用批次機制,而不至於會多載系統。 此屬性與 maxBatchSize 相似。

預設值為 1000。

maxBatchSize

選擇性 Int32 屬性。

指定每一批次處理的編譯的最大頁數。

預設值為 1000。

numRecompilesBeforeAppRestart

選擇性 Int32 屬性。

指定在應用程式重新啟動之前可發生的資源動態重新編譯數目。 全域和應用程式層級都支援這個屬性,但目錄層級並不支援。

NoteNote
每當組件失效和刪除失敗時,ASP.NET 便會增加 NumRecompilesBeforeAppRestart 屬性。

預設值為 15。

optimizeCompilations

選擇性 Boolean 屬性。

指定如果最上層檔案有變更,動態編譯是否會新編譯整個網站。 最上層檔案包括 Global.asax 檔,以及 Bin 與 App_Code 資料夾中所有的檔案。 如果為 True,則只會重新編譯有變更的檔案。

預設值為 False。

如需詳細資訊,請參閱 Understanding ASP.NET Dynamic Compilation

strict

選擇性 Boolean 屬性。

指定是否啟用 Visual Basic strict 編譯選項。

預設值為 False。

targetFramework

選擇性 String 屬性。

指定網站以之為設計目標的 .NET Framework 版本。

預設值為 Null。

如果省略此屬性,則目標版本是由 Web.config 檔中的其他設定和與網站相關聯的 IIS 應用程式集區所決定。 如需詳細資訊,請參閱 CompilationSection.TargetFramework.NET Framework Targeting for Web Projects

tempDirectory

選擇性 String 屬性。

指定編譯時用來儲存暫時檔案的目錄。

預設為空字串 ("")。

在使用空字串的情形下,如果目前的處理序具有必要的存取權限,則會將檔案儲存在 %FrameworkInstallLocation%\ 的 [暫存 ASP.NET 檔案] 目錄中。

請注意,只有具有高度信任權限的處理序可以存取 %FrameworkInstallLocation%\ 內的 [暫存 ASP.NET 檔案] 目錄。

urlLinePragmas

選擇性 Boolean 屬性。

指定編譯器是否應該使用 URL 而非實體路徑。

預設值為 False。

子項目

項目

描述

assemblies

定義在編譯 ASP.NET 資源期間使用的組件名稱集合。

buildProviders

定義用來編譯自訂資源檔的組建提供者集合。 如需詳細資訊,請參閱 BuildProvider 類別。

codeSubDirectories

定義已排序的子目錄集合,其中包含要在執行階段編譯的檔案。

compilers

定義編譯器選項的集合。

NoteNote
在 .NET Framework 2.0 (含) 以後版本中,system.codeDom 區段的 compilers 項目取代了這個項目。但是,使用 compilation 項目的 compilers 子項目仍然是有效的,而且將會覆寫位於 system.codedom 區段的 compilers 項目。

expressionBuilders

定義編譯期間所要使用的資源字串集合。 資源字串會使前置詞與運算式產生器產生關聯。

folderLevelBuildProviders

定義用來在特定資料夾中編譯自訂資源檔的組建提供者集合。 組建提供者會對應至副檔名,用來從指定類型的檔案產生程式碼。 如需詳細資訊,請參閱 FolderLevelBuildProvider 類別。

父項目

項目

描述

configuration

指定 Common Language Runtime 和 .NET Framework 應用程式所使用之每個組態檔中需要的根項目 (Root Element)。

system.web

指定組態檔中 ASP.NET 組態設定的根項目,並包含會設定 ASP.NET Web 應用程式行為的組態項目。

備註

compilation 項目會設定 ASP.NET 用來編譯應用程式的所有編譯設定。

在 .NET Framework 2.0 版中,system.codeDom 區段的 compilers 項目取代了 compilation 項目的 compilers 子項目。 但是,使用 compilation 項目的 compilers 子項目仍然是有效的,而且將會覆寫位於 system.codedom 區段的 compilers 項目。

預設組態

下列預設 compilation 項目不會明確地設定在 Machine.config 檔案或根 Web.config 檔案中。 然而,這個項目卻是應用程式所傳回的預設組態。 項目會加入根 Web.config 檔中的 assembliesbuildProvidersexpressionBuilders 集合。

<compilation 
   tempDirectory="" 
   debug="false" 
   strict="false" 
   explicit="true" 
   batch="true" 
   batchTimeout="900" 
   maxBatchSize="1000" 
   maxBatchGeneratedFileSize="1000" 
   numRecompilesBeforeAppRestart="15" 
   defaultLanguage="vb" 
   urlLinePragmas="false" 
   assemblyPostProcessorType=""
>
   <assemblies>
       <clear />
   </assemblies>
   <buildProviders>
       <clear />
   </buildProviders>
   <expressionBuilders>
       <clear />
   </expressionBuilders>
</compilation>

下列預設編譯項目是在 .NET Framework 1.1 版中的 Machine.config 檔中設定的。 除了版本號碼不同之外,.NET Framework 1.0 版中存在著相似的設定。

<compilation debug="false" explicit="true" defaultLanguage="vb">
   <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="1"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <compiler language="js;jscript;javascript" extension=".js" type="Microsoft.JScript.JScriptCodeProvider, Microsoft.JScript, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <compiler language="VJ#;VJS;VJSharp" extension=".jsl" type="Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/></compilers>
   <assemblies>
      <add assembly="mscorlib"/>
      <add assembly="System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <add assembly="System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <add assembly="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <add assembly="System.Web.Services, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <add assembly="System.Xml, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <add assembly="System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <add assembly="System.EnterpriseServices, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <add assembly="System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <add assembly="*"/>
   </assemblies>
</compilation>

範例

下列程式碼範例中,會示範如何設定應用程式的編譯設定。

<configuration>
   <system.web>
      <compilation defaultLanguage="VB"
         targetFramework="4.0"
         debug="true"
         numRecompilesBeforeAppRestart="15">
         <assemblies>
            <add assembly="ADODB"/>
            <add assembly="*"/>
         </assemblies>

         <codeSubDirectories>
           <add directoryName="mySubDir1"/>
           <add directoryName="mySubDir2"/>
           <add directoryName="mySubDir3"/>
         </codeSubDirectories>

         <buildProviders>
            <buildProvider 
               extension=".mafx" type="BuildProviderType, 
                          BuildProviderAssembly"
            />
        </buildProviders>
     </compilation>
   </system.web>
</configuration>

項目資訊

組態區段處理常式

CompilationSection

組態成員

Compilation

可設定的位置

Machine.config

根層次的 Web.config

應用程式層級的 Web.config

虛擬或實體目錄層級的 Web.config

需求

Microsoft Internet Information Services (IIS) 5.0、5.1 或 6.0

.NET Framework 1.0、1.1、2.0

Visual Studio 2003 或 Visual Studio 2005

請參閱

工作

How to: Configure Specific Folders Using Location Settings

How to: Lock ASP.NET Configuration Settings

參考

system.web 項目 (ASP.NET 設定結構描述)

編譯的 assemblies 項目 (ASP.NET 設定結構描述)

編譯的 buildProviders 項目 (ASP.NET 設定結構描述)

編譯的 codeSubDirectories 項目 (ASP.NET 設定結構描述)

編譯的 compilers 項目 (ASP.NET 設定結構描述)

編譯的 expressionBuilders 項目 (ASP.NET 設定結構描述)

configuration 項目 (一般設定結構描述)

System.Configuration

System.Web.Configuration

CompilationSection

Compilation

概念

ASP.NET Compilation Model

ASP.NET Web Page Syntax Overview

ASP.NET Configuration File Hierarchy

Securing Configuration

Configuration Inheritance

.NET Framework Targeting for Web Projects

其他資源

一般組態設定 (ASP.NET)

ASP.NET 組態設定

Configuring ASP.NET Applications

ASP.NET Configuration Files

ASP.NET Configuration API