CompilationSection 类

定义

定义用于支持 Web 应用程序的编译基础结构的配置设置。 此类不能被继承。

public ref class CompilationSection sealed : System::Configuration::ConfigurationSection
public sealed class CompilationSection : System.Configuration.ConfigurationSection
type CompilationSection = class
    inherit ConfigurationSection
Public NotInheritable Class CompilationSection
Inherits ConfigurationSection
继承

示例

此示例演示如何为节的 compilation 多个属性以声明方式指定值,该属性也可以作为类的成员 CompilationSection 进行访问。

以下配置文件示例演示如何以声明方式为 compilation 节指定值。

<system.web>  
  <compilation   
    tempDirectory=""   
    debug="False"   
    strict="False"   
    explicit="True"   
    batch="True"   
    batchTimeout="900"   
    maxBatchSize="1000"   
    maxBatchGeneratedFileSize="1000"   
    numRecompilesBeforeAppRestart="15"   
    defaultLanguage="vb"   
    targetFramework="4.0"   
    urlLinePragmas="False"   
    assemblyPostProcessorType="">  
    <assemblies>  
      <clear />  
    </assemblies>  
    <buildProviders>  
      <clear />  
    </buildProviders>  
    <expressionBuilders>  
      <clear />  
    </expressionBuilders>  
  </compilation>   
</system.web>  

下面的代码示例演示如何使用类的成员 CompilationSection

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Configuration;

#endregion

namespace Samples.Aspnet.SystemWebConfiguration
{
  class UsingCompilationSection
  {
    static void Main(string[] args)
    {
      try
      {
        // Set the path of the config file.
        string configPath = "";

        // Get the Web application configuration object.
        Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);

        // Get the section related object.
        CompilationSection configSection =
          (CompilationSection)config.GetSection("system.web/compilation");

        // Display title and info.
        Console.WriteLine("ASP.NET Configuration Info");
        Console.WriteLine();

        // Display Config details.
        Console.WriteLine("File Path: {0}",
          config.FilePath);
        Console.WriteLine("Section Path: {0}",
          configSection.SectionInformation.Name);

        // Display Assemblies collection count.
        Console.WriteLine("Assemblies Count: {0}",
          configSection.Assemblies.Count);

        // Display AssemblyPostProcessorType property.
        Console.WriteLine("AssemblyPostProcessorType: {0}", 
          configSection.AssemblyPostProcessorType);

        // Display Batch property.
        Console.WriteLine("Batch: {0}", configSection.Batch);

        // Set Batch property.
        configSection.Batch = true;

        // Display BatchTimeout property.
        Console.WriteLine("BatchTimeout: {0}",
          configSection.BatchTimeout);

        // Set BatchTimeout property.
        configSection.BatchTimeout = TimeSpan.FromMinutes(15);

          // Display BuildProviders collection count.
          Console.WriteLine("BuildProviders collection Count: {0}",
          configSection.BuildProviders.Count);

          // Display CodeSubDirectories collection count.
          Console.WriteLine("CodeSubDirectories Count: {0}",
        configSection.CodeSubDirectories.Count);

        // Display Compilers collection count.
        Console.WriteLine("Compilers Count: {0}",
        configSection.Compilers.Count);

        // Display Debug property.
        Console.WriteLine("Debug: {0}",
          configSection.Debug);

        // Set Debug property.
        configSection.Debug = false;

        // Display DefaultLanguage property.
        Console.WriteLine("DefaultLanguage: {0}",
          configSection.DefaultLanguage);

        // Set DefaultLanguage property.
        configSection.DefaultLanguage = "vb";

        // Display Explicit property.
        Console.WriteLine("Explicit: {0}",
          configSection.Explicit);

        // Set Explicit property.
        configSection.Explicit = true;

        // Display ExpressionBuilders collection count.
        Console.WriteLine("ExpressionBuilders Count: {0}",
          configSection.ExpressionBuilders.Count);

        // Display MaxBatchGeneratedFileSize property.
        Console.WriteLine("MaxBatchGeneratedFileSize: {0}", 
          configSection.MaxBatchGeneratedFileSize);

        // Set MaxBatchGeneratedFileSize property.
        configSection.MaxBatchGeneratedFileSize = 1000;

        // Display MaxBatchSize property.
        Console.WriteLine("MaxBatchSize: {0}", 
          configSection.MaxBatchSize);

        // Set MaxBatchSize property.
        configSection.MaxBatchSize = 1000;

        // Display NumRecompilesBeforeAppRestart property.
        Console.WriteLine("NumRecompilesBeforeAppRestart: {0}", 
          configSection.NumRecompilesBeforeAppRestart);

        // Set NumRecompilesBeforeAppRestart property.
        configSection.NumRecompilesBeforeAppRestart = 15;

        // Display Strict property.
        Console.WriteLine("Strict: {0}", 
          configSection.Strict);

        // Set Strict property.
        configSection.Strict = false;

        // Display TempDirectory property.
        Console.WriteLine("TempDirectory: {0}", configSection.TempDirectory);

        // Set TempDirectory property.
        configSection.TempDirectory = "myTempDirectory";

        // Display UrlLinePragmas property.
        Console.WriteLine("UrlLinePragmas: {0}", 
          configSection.UrlLinePragmas);

        // Set UrlLinePragmas property.
        configSection.UrlLinePragmas = false;

        // ExpressionBuilders Collection
        int i = 1;
        int j = 1;
        foreach (ExpressionBuilder expressionBuilder in configSection.ExpressionBuilders)
        {
          Console.WriteLine();
          Console.WriteLine("ExpressionBuilder {0} Details:", i);
          Console.WriteLine("Type: {0}", expressionBuilder.ElementInformation.Type);
          Console.WriteLine("Source: {0}", expressionBuilder.ElementInformation.Source);
          Console.WriteLine("LineNumber: {0}", expressionBuilder.ElementInformation.LineNumber);
          Console.WriteLine("Properties Count: {0}", expressionBuilder.ElementInformation.Properties.Count);
          j = 1;
          foreach (PropertyInformation propertyItem in expressionBuilder.ElementInformation.Properties)
          {
            Console.WriteLine("Property {0} Name: {1}", j, propertyItem.Name);
            Console.WriteLine("Property {0} Value: {1}", j, propertyItem.Value);
            j++;
          }
          i++;
        }

        // Update if not locked.
        if (!configSection.SectionInformation.IsLocked)
        {
          config.Save();
          Console.WriteLine("** Configuration updated.");
        }
        else
        {
          Console.WriteLine("** Could not update, section is locked.");
        }
      }

      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait
      Console.ReadLine();
    }
  }
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration

Namespace Samples.Aspnet.SystemWebConfiguration
  Class UsingRoleManagerSection
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String = ""

        ' Get the Web application configuration object.
        Dim config As System.Configuration.Configuration = _
         WebConfigurationManager.OpenWebConfiguration(configPath)

        ' Get the section related object.
        Dim configSection As System.Web.Configuration.CompilationSection = _
         CType(config.GetSection("system.web/compilation"), _
         System.Web.Configuration.CompilationSection)

        ' Display title and info.
        Console.WriteLine("ASP.NET Configuration Info")
        Console.WriteLine()

        ' Display Config details.
        Console.WriteLine("File Path: {0}", _
         config.FilePath)
        Console.WriteLine("Section Path: {0}", _
         configSection.SectionInformation.Name)

        ' Display Assemblies collection count.
        Console.WriteLine("Assemblies Count: {0}", _
         configSection.Assemblies.Count)

        ' Display AssemblyPostProcessorType property.
        Console.WriteLine("AssemblyPostProcessorType: {0}", _
         configSection.AssemblyPostProcessorType)

        ' Display Batch property.
        Console.WriteLine("Batch: {0}", _
         configSection.Batch)

        ' Set Batch property.
        configSection.Batch = True

        ' Display BatchTimeout property.
        Console.WriteLine("BatchTimeout: {0}", _
         configSection.BatchTimeout)

        ' Set BatchTimeout property.
        configSection.BatchTimeout = TimeSpan.FromMinutes(15)

        ' Display BuildProviders collection count.
        Console.WriteLine("BuildProviders collection count: {0}", _
         configSection.BuildProviders.Count)

        ' Display CodeSubDirectories property.
        Console.WriteLine("CodeSubDirectories: {0}", _
         configSection.CodeSubDirectories.Count)

        ' Display Compilers property.
        Console.WriteLine("Compilers: {0}", _
         configSection.Compilers.Count)

        ' Display Debug property.
        Console.WriteLine("Debug: {0}", _
         configSection.Debug)

        ' Set Debug property.
        configSection.Debug = False


        ' Display DefaultLanguage property.
        Console.WriteLine("DefaultLanguage: {0}", _
         configSection.DefaultLanguage)

        ' Set DefaultLanguage property.
        configSection.DefaultLanguage = "vb"

        ' Display Explicit property.
        Console.WriteLine("Explicit: {0}", _
         configSection.Explicit)

        ' Set Explicit property.
        configSection.Explicit = True

        ' Display ExpressionBuilders collection count.
        Console.WriteLine("ExpressionBuilders Count: {0}", _
         configSection.ExpressionBuilders.Count)

        ' Display MaxBatchGeneratedFileSize property.
        Console.WriteLine("MaxBatchGeneratedFileSize: {0}", _
         configSection.MaxBatchGeneratedFileSize)

        ' Set MaxBatchGeneratedFileSize property.
        configSection.MaxBatchGeneratedFileSize = 1000

        ' Display MaxBatchSize property.
        Console.WriteLine("MaxBatchSize: {0}", _
         configSection.MaxBatchSize)

        ' Set MaxBatchSize property.
        configSection.MaxBatchSize = 1000

        ' Display NumRecompilesBeforeAppRestart property.
        Console.WriteLine("NumRecompilesBeforeAppRestart: {0}", _
         configSection.NumRecompilesBeforeAppRestart)

        ' Set NumRecompilesBeforeAppRestart property.
        configSection.NumRecompilesBeforeAppRestart = 15

        ' Display Strict property.
        Console.WriteLine("Strict: {0}", _
         configSection.Strict)

        ' Set Strict property.
        configSection.Strict = False

        ' Display TempDirectory property.
        Console.WriteLine("TempDirectory: {0}", _
         configSection.TempDirectory)

        ' Set TempDirectory property.
        configSection.TempDirectory = "myTempDirectory"

        ' Display UrlLinePragmas property.
        Console.WriteLine("UrlLinePragmas: {0}", _
         configSection.UrlLinePragmas)

        ' Set UrlLinePragmas property.
        configSection.UrlLinePragmas = False

        ' ExpressionBuilders Collection
        Dim i = 1
        Dim j = 1
        For Each expressionBuilder As ExpressionBuilder In configSection.ExpressionBuilders()
          Console.WriteLine()
          Console.WriteLine("ExpressionBuilder {0} Details:", i)
          Console.WriteLine("Type: {0}", expressionBuilder.ElementInformation.Type)
          Console.WriteLine("Source: {0}", expressionBuilder.ElementInformation.Source)
          Console.WriteLine("LineNumber: {0}", expressionBuilder.ElementInformation.LineNumber)
          Console.WriteLine("Properties Count: {0}", expressionBuilder.ElementInformation.Properties.Count)
          j = 1
          For Each propertyItem As PropertyInformation In expressionBuilder.ElementInformation.Properties
            Console.WriteLine("Property {0} Name: {1}", j, propertyItem.Name)
            Console.WriteLine("Property {0} Value: {1}", j, propertyItem.Value)
            j = j + 1
          Next
          i = i + 1
        Next

        ' Update if not locked.
        If Not configSection.SectionInformation.IsLocked Then
          config.Save()
          Console.WriteLine("** Configuration updated.")
        Else
          Console.WriteLine("** Could not update, section is locked.")
        End If

      Catch e As Exception
        ' Unknown error.
        Console.WriteLine(e.ToString())
      End Try

      ' Display and wait
      Console.ReadLine()
    End Sub
  End Class
End Namespace

注解

CompilationSection 类提供了一种以编程方式访问和修改配置文件节内容 compilation 的方法。

构造函数

CompilationSection()

使用默认设置初始化 CompilationSection 类的新实例。

属性

Assemblies

获取 AssemblyCollectionCompilationSection

AssemblyPostProcessorType

获取或设置一个值,该值指定程序集的后续处理编译步骤。

Batch

获取或设置一个值,该值指示是否尝试批编译。

BatchTimeout

获取或设置批处理编译的超时期限(以秒为单位)。

BuildProviders

获取 CompilationSection 类的 BuildProviderCollection 集合。

CodeSubDirectories

获取 CodeSubDirectoriesCollectionCompilationSection

Compilers

获取 CompilationSection 类的 CompilerCollection 集合。

ControlBuilderInterceptorType

获取或设置一个字符串,表示用于截获 ControlBuilder 对象和配置容器的对象类型。

CurrentConfiguration

获取对顶级 Configuration 实例的引用,该实例表示当前 ConfigurationElement 实例所属的配置层次结构。

(继承自 ConfigurationElement)
Debug

获取或设置一个值,该值指定是要编译发布二进制文件还是调试二进制文件。

DefaultLanguage

获取或设置要在动态编译文件中使用的默认编程语言。

DisableObsoleteWarnings

获取或设置编译部分的“disableObsoleteWarnings”配置值是否已设置。

ElementInformation

获取包含 ConfigurationElement 对象的不可自定义的信息和功能的 ElementInformation 对象。

(继承自 ConfigurationElement)
ElementProperty

获取表示 ConfigurationElement 对象本身的 ConfigurationElementProperty 对象。

(继承自 ConfigurationElement)
EnablePrefetchOptimization

获取或设置一个值,该值指示 ASP.NET 应用程序是否可以利用Windows 8预提取功能。

EvaluationContext

获取 ConfigurationElement 对象的 ContextInformation 对象。

(继承自 ConfigurationElement)
Explicit

获取或设置一个值,该值指示是否使用 Microsoft Visual Basic explicit 编译选项。

ExpressionBuilders

获取 ExpressionBuilderCollectionCompilationSection

FolderLevelBuildProviders

获取 FolderLevelBuildProviderCollection 类的 CompilationSection 集合,表示在编译过程中使用的生成提供程序。

HasContext

获取一个值,该值指示 CurrentConfiguration 属性是否为 null

(继承自 ConfigurationElement)
Item[ConfigurationProperty]

获取或设置此配置元素的属性或特性。

(继承自 ConfigurationElement)
Item[String]

获取或设置此配置元素的属性、特性或子元素。

(继承自 ConfigurationElement)
LockAllAttributesExcept

获取被锁定的特性的集合。

(继承自 ConfigurationElement)
LockAllElementsExcept

获取被锁定的元素的集合。

(继承自 ConfigurationElement)
LockAttributes

获取被锁定的特性的集合。

(继承自 ConfigurationElement)
LockElements

获取被锁定的元素的集合。

(继承自 ConfigurationElement)
LockItem

获取或设置一个值,该值指示是否已锁定该元素。

(继承自 ConfigurationElement)
MaxBatchGeneratedFileSize

获取或设置每个成批编译生成的源文件的最大组合大小。

MaxBatchSize

获取或设置每个成批编译的最大页数。

MaxConcurrentCompilations

获取或设置编译部分的“maxConcurrentCompilations”配置值是否已设置。

NumRecompilesBeforeAppRestart

获取或设置应用程序重新启动前可发生的资源的动态重新编译的次数。

OptimizeCompilations

获取或设置一个值,该值指示是否必须优化编译。

ProfileGuidedOptimizations

获取或设置一个值,该值指示是否针对所部署环境优化了应用程序。

Properties

获取属性的集合。

(继承自 ConfigurationElement)
SectionInformation

获取一个 SectionInformation 对象,该对象包含 ConfigurationSection 对象的不可自定义的信息和功能。

(继承自 ConfigurationSection)
Strict

获取或设置 Visual Basic strict 编译选项。

TargetFramework

获取或设置网站的目标 .NET Framework 的版本。

TempDirectory

获取或设置一个值,该值指定要在编译期间用于临时文件存储的目录。

UrlLinePragmas

获取或设置一个值,该值指示编译器指令使用物理路径还是 URL。

方法

DeserializeElement(XmlReader, Boolean)

从配置文件读取 XML。

(继承自 ConfigurationElement)
DeserializeSection(XmlReader)

从配置文件读取 XML。

(继承自 ConfigurationSection)
Equals(Object)

将当前的 ConfigurationElement 实例与指定的对象进行比较。

(继承自 ConfigurationElement)
GetHashCode()

获取表示当前 ConfigurationElement 实例的唯一值。

(继承自 ConfigurationElement)
GetRuntimeObject()

在派生的类中重写时返回自定义对象。

(继承自 ConfigurationSection)
GetTransformedAssemblyString(String)

返回指定程序集名称的转换版本。

(继承自 ConfigurationElement)
GetTransformedTypeString(String)

返回指定类型名称的转换版本。

(继承自 ConfigurationElement)
GetType()

获取当前实例的 Type

(继承自 Object)
Init()

ConfigurationElement 对象设置为其初始状态。

(继承自 ConfigurationElement)
InitializeDefault()

用于初始化 ConfigurationElement 对象的默认值集。

(继承自 ConfigurationElement)
IsModified()

指示自上次在派生类中实现此配置元素时保存或加载以来是否对其进行过修改。

(继承自 ConfigurationSection)
IsReadOnly()

获取一个值,该值指示 ConfigurationElement 对象是否为只读。

(继承自 ConfigurationElement)
ListErrors(IList)

将此 ConfigurationElement 对象以及所有子元素中无效属性的错误添加到传递的列表中。

(继承自 ConfigurationElement)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnDeserializeUnrecognizedAttribute(String, String)

获取一个值,该值指示反序列化过程中是否遇到未知特性。

(继承自 ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

获取一个值,该值指示反序列化过程中是否遇到未知元素。

(继承自 ConfigurationElement)
OnRequiredPropertyNotFound(String)

找不到所需属性时引发异常。

(继承自 ConfigurationElement)
PostDeserialize()

反序列化后调用。

(继承自 ConfigurationElement)
PreSerialize(XmlWriter)

在序列化之前调用。

(继承自 ConfigurationElement)
Reset(ConfigurationElement)

重置 ConfigurationElement 对象的内部状态,包括锁和属性集合。

(继承自 ConfigurationElement)
ResetModified()

在派生类中实现时,将 IsModified() 方法的值重置为 false

(继承自 ConfigurationSection)
SerializeElement(XmlWriter, Boolean)

当在派生类中实现后,将此配置元素的内容写入配置文件。

(继承自 ConfigurationElement)
SerializeSection(ConfigurationElement, String, ConfigurationSaveMode)

创建一个包含 ConfigurationSection 对象的分离视图的 XML 字符串,作为单独的节写入到文件中。

(继承自 ConfigurationSection)
SerializeToXmlElement(XmlWriter, String)

当在派生类中实现后,将此配置元素的外部标记写入配置文件。

(继承自 ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

将属性设置为指定值。

(继承自 ConfigurationElement)
SetReadOnly()

设置 ConfigurationElement 对象及所有子元素的 IsReadOnly() 属性。

(继承自 ConfigurationElement)
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName)

指示当为指定目标版本的.NET Framework序列化配置对象层次结构时,是否应序列化指定的元素。

(继承自 ConfigurationSection)
ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement)

指示当为指定的目标版本的.NET Framework序列化配置对象层次结构时,是否应序列化指定的属性。

(继承自 ConfigurationSection)
ShouldSerializeSectionInTargetVersion(FrameworkName)

指示在为指定目标版本的.NET Framework序列化配置对象层次结构时,是否应序列化当前ConfigurationSection实例。

(继承自 ConfigurationSection)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

修改 ConfigurationElement 对象以移除所有不应该保存的值。

(继承自 ConfigurationElement)

适用于

另请参阅