共用方式為


<compiler> Element

Specifies the compiler configuration attributes for a language provider.

<compiler
  language="languageName[;...;...]"
  extension="fileExtension[;...;...]"
  type="typeName, assemblyName"
  warningLevel="number"
  compilerOptions="option1 option2"
/>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Description

compilerOptions

Optional attribute.

Specifies additional compiler-specific arguments for compilation.

extension

Required attribute.

Provides a semicolon-separated list of file name extensions used by source files for the language provider. For example, ".cs".

language

Required attribute.

Provides a semicolon-separated list of language names supported by the language provider. For example, "c#;cs;csharp".

type

Required attribute.

Specifies the type name of the language provider, including the name of the assembly containing the provider implementation. The type name must meet the requirements defined in Specifying Fully Qualified Type Names.

warningLevel

Optional attribute.

Specifies the default compiler warning level; determines the level at which the language provider treats compilation warnings as errors.

Child Elements

None.

Parent Elements

Element Description

<configuration> Element

The root element in every configuration file used by the common language runtime and .NET Framework applications.

<system.codedom> Element

Specifies compiler configuration settings for available language providers.

<compilers> Element

Container for compiler configuration elements; contains zero or more <compiler> elements.

Remarks

Each <compiler> element specifies the compiler configuration attributes for a specific language provider. The provider extends the System.CodeDom.Compiler.CodeDomProvider class for a specific language; the <compiler> element defines the compiler and code generator settings for the language provider.

The .NET Framework defines the initial compiler settings in the machine configuration file (Machine.config). Developers and compiler vendors can add configuration settings for a new CodeDomProvider implementation. Use the System.CodeDom.Compiler.CodeDomProvider.GetAllCompilerInfo method to programmatically enumerate language provider and compiler configuration settings on a computer.

Compiler elements in the application or Web configuration file can supplement or override the settings in the machine configuration file. If more than one provider implementation is configured for the same language name or the same file extension, the last matching configuration overrides any previous configured providers for that language name or file extension.

Configuration File

This element can be used in the machine configuration file and the application configuration file.

Example

The following example illustrates a typical compiler configuration element.

<configuration>
  <system.codedom>
    <compilers>
      <!-- zero or more compiler elements -->
      <compiler
        language="c#;cs;csharp"
        extension=".cs"
        type="Microsoft.CSharp.CSharpCodeProvider, System, 
          Version=2.0.3600.0, Culture=neutral, 
          PublicKeyToken=b77a5c561934e089"
        compilerOptions=""
        warningLevel="1" />
    </compilers>
  </system.codedom>
</configuration>

See Also

Reference

<compilers> Element
compiler Element for compilers for compilation (ASP.NET Settings Schema)
CompilerInfo
CodeDomProvider

Concepts

Specifying Fully Qualified Type Names

Other Resources

Configuration File Schema for the .NET Framework