CompilerParameters 类

定义

表示用于调用编译器的参数。Represents the parameters used to invoke a compiler.

public ref class CompilerParameters
public class CompilerParameters
[System.Runtime.InteropServices.ComVisible(false)]
public class CompilerParameters
[System.Serializable]
public class CompilerParameters
type CompilerParameters = class
Public Class CompilerParameters
继承
CompilerParameters
派生
属性

示例

下面的示例为简单的 Hello World 程序生成一个 CodeDOM 源关系图。The following example builds a CodeDOM source graph for a simple Hello World program. 然后,将该源保存到文件中,将其编译为可执行文件,然后运行。The source is then saved to a file, compiled into an executable, and run. CompileCode 方法演示如何使用 CompilerParameters 类指定各种编译器设置和选项。The CompileCode method illustrates how to use the CompilerParameters class to specify various compiler settings and options.

using namespace System;
using namespace System::CodeDom;
using namespace System::CodeDom::Compiler;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::IO;
using namespace System::Diagnostics;

// Build a Hello World program graph using System.CodeDom types.
static CodeCompileUnit^ BuildHelloWorldGraph()
{
   // Create a new CodeCompileUnit to contain the program graph.
   CodeCompileUnit^ compileUnit = gcnew CodeCompileUnit;
   
   // Declare a new namespace called Samples.
   CodeNamespace^ samples = gcnew CodeNamespace( "Samples" );
   // Add the new namespace to the compile unit.
   compileUnit->Namespaces->Add( samples );
   
   // Add the new namespace import for the System namespace.
   samples->Imports->Add( gcnew CodeNamespaceImport( "System" ) );
   
   // Declare a new type called Class1.
   CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration( "Class1" );
   // Add the new type to the namespace's type collection.
   samples->Types->Add( class1 );
   
   // Declare a new code entry point method
   CodeEntryPointMethod^ start = gcnew CodeEntryPointMethod;
   
   // Create a type reference for the System::Console class.
   CodeTypeReferenceExpression^ csSystemConsoleType =
      gcnew CodeTypeReferenceExpression( "System.Console" );
   
   // Build a Console::WriteLine statement.
   CodeMethodInvokeExpression^ cs1 = gcnew CodeMethodInvokeExpression(
      csSystemConsoleType, "WriteLine",
      gcnew CodePrimitiveExpression( "Hello World!" ) );
   
   // Add the WriteLine call to the statement collection.
   start->Statements->Add( cs1 );
   
   // Build another Console::WriteLine statement.
   CodeMethodInvokeExpression^ cs2 = gcnew CodeMethodInvokeExpression(
      csSystemConsoleType, "WriteLine",
      gcnew CodePrimitiveExpression( "Press the Enter key to continue." ) );
   // Add the WriteLine call to the statement collection.
   start->Statements->Add( cs2 );
   
   // Build a call to System::Console::ReadLine.
   CodeMethodReferenceExpression^ csReadLine = gcnew CodeMethodReferenceExpression(
      csSystemConsoleType, "ReadLine" );
   CodeMethodInvokeExpression^ cs3 = gcnew CodeMethodInvokeExpression(
      csReadLine,gcnew array<CodeExpression^>(0) );
   
   // Add the ReadLine statement.
   start->Statements->Add( cs3 );
   
   // Add the code entry point method to the Members collection
   // of the type.
   class1->Members->Add( start );

   return compileUnit;
}

static String^ GenerateCode( CodeDomProvider^ provider, CodeCompileUnit^ compileunit )
{
   // Build the source file name with the language extension (vb, cs, js).
   String^ sourceFile = String::Empty;

      if ( provider->FileExtension->StartsWith( "." ) )
      {
         sourceFile = String::Concat( "HelloWorld", provider->FileExtension );
      }
      else
      {
         sourceFile = String::Concat( "HelloWorld.", provider->FileExtension );
      }

      // Create a TextWriter to a StreamWriter to an output file.
      IndentedTextWriter^ tw = gcnew IndentedTextWriter(
         gcnew StreamWriter( sourceFile,false ),"    " );
      // Generate source code using the code generator.
      provider->GenerateCodeFromCompileUnit( compileunit, tw, gcnew CodeGeneratorOptions );
      // Close the output file.
      tw->Close();
   return sourceFile;
}

static bool CompileCode( CodeDomProvider^ provider,
   String^ sourceFile,
   String^ exeFile )
{

   CompilerParameters^ cp = gcnew CompilerParameters;
   if ( !cp)  
   {
      return false;
   }

   // Generate an executable instead of 
   // a class library.
   cp->GenerateExecutable = true;
   
   // Set the assembly file name to generate.
   cp->OutputAssembly = exeFile;
   
   // Generate debug information.
   cp->IncludeDebugInformation = true;
   
   // Add an assembly reference.
   cp->ReferencedAssemblies->Add( "System.dll" );
   
   // Save the assembly as a physical file.
   cp->GenerateInMemory = false;
   
   // Set the level at which the compiler 
   // should start displaying warnings.
   cp->WarningLevel = 3;
   
   // Set whether to treat all warnings as errors.
   cp->TreatWarningsAsErrors = false;
   
   // Set compiler argument to optimize output.
   cp->CompilerOptions = "/optimize";
   
   // Set a temporary files collection.
   // The TempFileCollection stores the temporary files
   // generated during a build in the current directory,
   // and does not delete them after compilation.
   cp->TempFiles = gcnew TempFileCollection( ".",true );

   if ( provider->Supports( GeneratorSupport::EntryPointMethod ) )
   {
      // Specify the class that contains 
      // the main method of the executable.
      cp->MainClass = "Samples.Class1";
   }

   if ( Directory::Exists( "Resources" ) )
   {
      if ( provider->Supports( GeneratorSupport::Resources ) )
      {
         // Set the embedded resource file of the assembly.
         // This is useful for culture-neutral resources,
         // or default (fallback) resources.
         cp->EmbeddedResources->Add( "Resources\\Default.resources" );

         // Set the linked resource reference files of the assembly.
         // These resources are included in separate assembly files,
         // typically localized for a specific language and culture.
         cp->LinkedResources->Add( "Resources\\nb-no.resources" );
      }
   }

   // Invoke compilation.
   CompilerResults^ cr = provider->CompileAssemblyFromFile( cp, sourceFile );

   if ( cr->Errors->Count > 0 )
   {
      // Display compilation errors.
      Console::WriteLine( "Errors building {0} into {1}",
         sourceFile, cr->PathToAssembly );
      for each ( CompilerError^ ce in cr->Errors )
      {
         Console::WriteLine( "  {0}", ce->ToString() );
         Console::WriteLine();
      }
   }
   else
   {
      Console::WriteLine( "Source {0} built into {1} successfully.",
         sourceFile, cr->PathToAssembly );
   }

   // Return the results of compilation.
   if ( cr->Errors->Count > 0 )
   {
      return false;
   }
   else
   {
      return true;
   }
}

[STAThread]
void main()
{
   String^ exeName = "HelloWorld.exe";
   CodeDomProvider^ provider = nullptr;

   Console::WriteLine( "Enter the source language for Hello World (cs, vb, etc):" );
   String^ inputLang = Console::ReadLine();
   Console::WriteLine();

   if ( CodeDomProvider::IsDefinedLanguage( inputLang ) )
   {
      CodeCompileUnit^ helloWorld = BuildHelloWorldGraph();
      provider = CodeDomProvider::CreateProvider( inputLang );
      if ( helloWorld && provider )
      {
         String^ sourceFile = GenerateCode( provider, helloWorld );
         Console::WriteLine( "HelloWorld source code generated." );
         if ( CompileCode( provider, sourceFile, exeName ) )
         {
            Console::WriteLine( "Starting HelloWorld executable." );
            Process::Start( exeName );
         }
      }
   }

   if ( provider == nullptr )
   {
      Console::WriteLine( "There is no CodeDomProvider for the input language." );
   }
}
using System;
using System.Globalization;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Diagnostics;

namespace CompilerParametersExample
{
    class CompileClass
    {
        // Build a Hello World program graph using System.CodeDom types.
        public static CodeCompileUnit BuildHelloWorldGraph()
        {            
            // Create a new CodeCompileUnit to contain the program graph
            CodeCompileUnit compileUnit = new CodeCompileUnit();

            // Declare a new namespace called Samples.
            CodeNamespace samples = new CodeNamespace("Samples");
            // Add the new namespace to the compile unit.
            compileUnit.Namespaces.Add( samples );

            // Add the new namespace import for the System namespace.
            samples.Imports.Add( new CodeNamespaceImport("System") );            

            // Declare a new type called Class1.
            CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");
            // Add the new type to the namespace's type collection.
            samples.Types.Add(class1);
            
            // Declare a new code entry point method.
            CodeEntryPointMethod start = new CodeEntryPointMethod();

            // Create a type reference for the System.Console class.
            CodeTypeReferenceExpression csSystemConsoleType = new CodeTypeReferenceExpression("System.Console");

            // Build a Console.WriteLine statement.
            CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression( 
                csSystemConsoleType, "WriteLine", 
                new CodePrimitiveExpression("Hello World!") );

            // Add the WriteLine call to the statement collection.
            start.Statements.Add(cs1);

            // Build another Console.WriteLine statement.
            CodeMethodInvokeExpression cs2 = new CodeMethodInvokeExpression(
                csSystemConsoleType, "WriteLine",
                new CodePrimitiveExpression("Press the Enter key to continue.") );
            // Add the WriteLine call to the statement collection.
            start.Statements.Add(cs2);

            // Build a call to System.Console.ReadLine.
            CodeMethodInvokeExpression csReadLine = new CodeMethodInvokeExpression(
                csSystemConsoleType, "ReadLine");

            // Add the ReadLine statement.
            start.Statements.Add(csReadLine);

            // Add the code entry point method to the Members
            // collection of the type.
            class1.Members.Add( start );

            return compileUnit;
        }

        public static String GenerateCode(CodeDomProvider provider, 
                                          CodeCompileUnit compileunit)
        {
            // Build the source file name with the language
            // extension (vb, cs, js).
            String sourceFile;
            if (provider.FileExtension[0] == '.')
            {
                sourceFile = "HelloWorld" + provider.FileExtension;
            }
            else 
            {
                sourceFile = "HelloWorld." + provider.FileExtension;
            }

            // Create a TextWriter to a StreamWriter to an output file.
            IndentedTextWriter tw = new IndentedTextWriter(new StreamWriter(sourceFile, false), "    ");
            // Generate source code using the code provider.
            provider.GenerateCodeFromCompileUnit(compileunit, tw, new CodeGeneratorOptions());
            // Close the output file.
            tw.Close();            

            return sourceFile;
        }
    
        public static bool CompileCode(CodeDomProvider provider, 
            String sourceFile, 
            String exeFile)
        {

            CompilerParameters cp = new CompilerParameters();

            // Generate an executable instead of 
            // a class library.
            cp.GenerateExecutable = true;

            // Set the assembly file name to generate.
            cp.OutputAssembly = exeFile;

            // Generate debug information.
            cp.IncludeDebugInformation = true;

            // Add an assembly reference.
            cp.ReferencedAssemblies.Add( "System.dll" );

            // Save the assembly as a physical file.
            cp.GenerateInMemory = false;

            // Set the level at which the compiler 
            // should start displaying warnings.
            cp.WarningLevel = 3;

            // Set whether to treat all warnings as errors.
            cp.TreatWarningsAsErrors = false;
            
            // Set compiler argument to optimize output.
            cp.CompilerOptions = "/optimize";

            // Set a temporary files collection.
            // The TempFileCollection stores the temporary files
            // generated during a build in the current directory,
            // and does not delete them after compilation.
            cp.TempFiles = new TempFileCollection(".", true);

            if (provider.Supports(GeneratorSupport.EntryPointMethod))
            {
                // Specify the class that contains 
                // the main method of the executable.
                cp.MainClass = "Samples.Class1";
            }
  
            if (Directory.Exists("Resources"))
            {
                if (provider.Supports(GeneratorSupport.Resources))
                {
                    // Set the embedded resource file of the assembly.
                    // This is useful for culture-neutral resources,
                    // or default (fallback) resources.
                    cp.EmbeddedResources.Add("Resources\\Default.resources");

                    // Set the linked resource reference files of the assembly.
                    // These resources are included in separate assembly files,
                    // typically localized for a specific language and culture.
                    cp.LinkedResources.Add("Resources\\nb-no.resources");
                }
            }

            // Invoke compilation.
            CompilerResults cr = provider.CompileAssemblyFromFile(cp, sourceFile);

            if(cr.Errors.Count > 0)
            {
                // Display compilation errors.
                Console.WriteLine("Errors building {0} into {1}",  
                    sourceFile, cr.PathToAssembly);
                foreach(CompilerError ce in cr.Errors)
                {
                    Console.WriteLine("  {0}", ce.ToString());
                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("Source {0} built into {1} successfully.",
                    sourceFile, cr.PathToAssembly);
                Console.WriteLine("{0} temporary files created during the compilation.",
                    cp.TempFiles.Count.ToString());
            }
          
            // Return the results of compilation.
            if (cr.Errors.Count > 0)
            {
                return false;
            }
            else 
            {
                return true;
            }
        }
 
        [STAThread]
        static void Main() 
        {
            CodeDomProvider provider = null;
            String exeName = "HelloWorld.exe";

            Console.WriteLine("Enter the source language for Hello World (cs, vb, etc):");
            String inputLang = Console.ReadLine();
            Console.WriteLine();

            if (CodeDomProvider.IsDefinedLanguage(inputLang))
            {
                provider = CodeDomProvider.CreateProvider(inputLang);
            }

            if (provider == null)
            {
                Console.WriteLine("There is no CodeDomProvider for the input language.");
            }
            else 
            {
                CodeCompileUnit helloWorld = BuildHelloWorldGraph();

                String sourceFile = GenerateCode(provider, helloWorld);

                Console.WriteLine("HelloWorld source code generated.");

                if (CompileCode(provider, sourceFile, exeName ))
                {
                    Console.WriteLine("Starting HelloWorld executable.");
                    Process.Start(exeName);            
                }
            }
        }
    }
}
Imports System.Globalization
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports System.Collections
Imports System.ComponentModel
Imports System.IO
Imports System.Diagnostics

Namespace CompilerParametersExample

    Class CompileClass

        ' Build a Hello World program graph using System.CodeDom types.
        Public Shared Function BuildHelloWorldGraph() As CodeCompileUnit

            ' Create a new CodeCompileUnit to contain the program graph.
            Dim compileUnit As New CodeCompileUnit()

            ' Declare a new namespace called Samples.
            Dim samples As New CodeNamespace("Samples")

            ' Add the new namespace to the compile unit.
            compileUnit.Namespaces.Add(samples)

            ' Add the new namespace import for the System namespace.
            samples.Imports.Add(New CodeNamespaceImport("System"))

            ' Declare a new type called Class1.
            Dim Class1 As New CodeTypeDeclaration("Class1")

            ' Add the new type to the namespace's type collection.
            samples.Types.Add(class1)

            ' Declare a new code entry point method
            Dim start As New CodeEntryPointMethod()

            ' Create a type reference for the System.Console class.
            Dim csSystemConsoleType As New CodeTypeReferenceExpression( _
                "System.Console")

            ' Build a Console.WriteLine statement.
            Dim cs1 As New CodeMethodInvokeExpression( _
                csSystemConsoleType, "WriteLine", _
                New CodePrimitiveExpression("Hello World!"))

            ' Add the WriteLine call to the statement collection.
            start.Statements.Add(cs1)

            ' Build another Console.WriteLine statement.
            Dim cs2 As New CodeMethodInvokeExpression( _
                csSystemConsoleType, "WriteLine", _
                New CodePrimitiveExpression("Press the Enter key to continue."))

            ' Add the WriteLine call to the statement collection.
            start.Statements.Add(cs2)

            ' Build a call to System.Console.ReadLine.
            Dim csReadLine As New CodeMethodInvokeExpression( _
                csSystemConsoleType, "ReadLine")

            ' Add the ReadLine statement.
            start.Statements.Add(csReadLine)

            ' Add the code entry point method to the Members
            ' collection of the type.
            class1.Members.Add(start)

            Return compileUnit
        End Function


        Public Shared Function GenerateCode(ByVal provider As CodeDomProvider, _
        ByVal compileunit As CodeCompileUnit) As String

            ' Build the source file name with the language extension (vb, cs, js).
            Dim sourceFile As String
            If provider.FileExtension.StartsWith(".") Then
                sourceFile = "HelloWorld" + provider.FileExtension
            Else
                sourceFile = "HelloWorld." + provider.FileExtension
            End If

            ' Create a TextWriter to a StreamWriter to an output file.
            Dim tw As New IndentedTextWriter(New StreamWriter(sourceFile, False), "    ")

            ' Generate source code using the code provider.
            provider.GenerateCodeFromCompileUnit(compileunit, tw, _
                New CodeGeneratorOptions())

            ' Close the output file.
            tw.Close()

            Return sourceFile
        End Function 'GenerateCode


        Public Shared Function CompileCode(ByVal provider As CodeDomProvider, _
        ByVal sourceFile As String, ByVal exeFile As String) As Boolean

            Dim cp As New CompilerParameters()

            ' Generate an executable instead of 
            ' a class library.
            cp.GenerateExecutable = True

            ' Set the assembly file name to generate.
            cp.OutputAssembly = exeFile

            ' Generate debug information.
            cp.IncludeDebugInformation = True

            ' Add an assembly reference.
            cp.ReferencedAssemblies.Add("System.dll")

            ' Save the assembly as a physical file.
            cp.GenerateInMemory = False

            ' Set the level at which the compiler 
            ' should start displaying warnings.
            cp.WarningLevel = 3

            ' Set whether to treat all warnings as errors.
            cp.TreatWarningsAsErrors = False

            ' Set compiler argument to optimize output.
            cp.CompilerOptions = "/optimize"

            ' Set a temporary files collection.
            ' The TempFileCollection stores the temporary files
            ' generated during a build in the current directory,
            ' and does not delete them after compilation.
            cp.TempFiles = New TempFileCollection(".", True)

            If provider.Supports(GeneratorSupport.EntryPointMethod) Then
                ' Specify the class that contains
                ' the main method of the executable.
                cp.MainClass = "Samples.Class1"
            End If


            If Directory.Exists("Resources") Then
                If provider.Supports(GeneratorSupport.Resources) Then
                    ' Set the embedded resource file of the assembly.
                    ' This is useful for culture-neutral resources,
                    ' or default (fallback) resources.
                    cp.EmbeddedResources.Add("Resources\Default.resources")

                    ' Set the linked resource reference files of the assembly.
                    ' These resources are included in separate assembly files,
                    ' typically localized for a specific language and culture.
                    cp.LinkedResources.Add("Resources\nb-no.resources")
                End If
            End If

            ' Invoke compilation.
            Dim cr As CompilerResults = _
                provider.CompileAssemblyFromFile(cp, sourceFile)

            If cr.Errors.Count > 0 Then
                ' Display compilation errors.
                Console.WriteLine("Errors building {0} into {1}", _
                    sourceFile, cr.PathToAssembly)
                Dim ce As CompilerError
                For Each ce In cr.Errors
                    Console.WriteLine("  {0}", ce.ToString())
                    Console.WriteLine()
                Next ce
            Else
                Console.WriteLine("Source {0} built into {1} successfully.", _
                    sourceFile, cr.PathToAssembly)
                Console.WriteLine("{0} temporary files created during the compilation.", _
                        cp.TempFiles.Count.ToString())
            End If

            ' Return the results of compilation.
            If cr.Errors.Count > 0 Then
                Return False
            Else
                Return True
            End If
        End Function 'CompileCode

        <STAThread()> _
        Shared Sub Main()
            Dim exeName As String = "HelloWorld.exe"
            Dim provider As CodeDomProvider = Nothing

            Console.WriteLine("Enter the source language for Hello World (cs, vb, etc):")
            Dim inputLang As String = Console.ReadLine()
            Console.WriteLine()

            If CodeDomProvider.IsDefinedLanguage(inputLang) Then
                Dim helloWorld As CodeCompileUnit = BuildHelloWorldGraph()
                provider = CodeDomProvider.CreateProvider(inputLang)

                Dim sourceFile As String
                sourceFile = GenerateCode(provider, helloWorld)

                Console.WriteLine("HelloWorld source code generated.")

                If CompileCode(provider, sourceFile, exeName) Then
                    Console.WriteLine("Starting HelloWorld executable.")
                    Process.Start(exeName)
                End If
            End If

            If provider Is Nothing Then
                Console.WriteLine("There is no CodeDomProvider for the input language.")
            End If
        End Sub

    End Class
End Namespace

注解

CompilerParameters 对象表示 ICodeCompiler 接口的设置和选项。A CompilerParameters object represents the settings and options for an ICodeCompiler interface.

如果要编译可执行程序,则必须将 GenerateExecutable 属性设置为 trueIf you are compiling an executable program, you must set the GenerateExecutable property to true. GenerateExecutable 设置为 false时,编译器将生成一个类库。When the GenerateExecutable is set to false, the compiler will generate a class library. 默认情况下,会将新的 CompilerParameters 初始化,并将其 GenerateExecutable 属性设置为 "false"。By default, a new CompilerParameters is initialized with its GenerateExecutable property set to false. 如果要从 CodeDOM 图编译可执行文件,则必须在该图中定义 CodeEntryPointMethodIf you are compiling an executable from a CodeDOM graph, a CodeEntryPointMethod must be defined in the graph. 如果有多个代码入口点,则可以通过将类的名称设置为 MainClass 属性来指示定义要使用的入口点的类。If there are multiple code entry points, you can indicate the class that defines the entry point to use by setting the name of the class to the MainClass property.

您可以在 OutputAssembly 属性中指定输出程序集的文件名。You can specify a file name for the output assembly in the OutputAssembly property. 否则,将使用默认的输出文件名。Otherwise, a default output file name will be used. 若要在生成的程序集中包含调试信息,请将 IncludeDebugInformation 属性设置为 trueTo include debug information in a generated assembly, set the IncludeDebugInformation property to true. 如果项目引用了任何程序集,则必须将程序集名称指定为 StringCollection 中的项设置为调用编译时使用的 CompilerParametersReferencedAssemblies 属性。If your project references any assemblies, you must specify the assembly names as items in a StringCollection set to the ReferencedAssemblies property of the CompilerParameters used when invoking compilation.

可以通过将 GenerateInMemory 属性设置为 true来编译写入内存而不是磁盘的程序集。You can compile an assembly that is written to memory rather than disk by setting the GenerateInMemory property to true. 在内存中生成程序集时,代码可从 CompiledAssemblyCompilerResults 属性中获取对生成的程序集的引用。When an assembly is generated in memory, your code can obtain a reference to the generated assembly from the CompiledAssembly property of a CompilerResults. 如果将程序集写入磁盘,则可以从 CompilerResultsPathToAssembly 属性获取生成的程序集的路径。If an assembly is written to disk, you can obtain the path to the generated assembly from the PathToAssembly property of a CompilerResults.

若要指定暂停编译的警告等级,请将 WarningLevel 属性设置为一个整数,表示暂停编译的警告等级。To specify a warning level at which to halt compilation, set the WarningLevel property to an integer that represents the warning level at which to halt compilation. 你还可以通过将 TreatWarningsAsErrors 属性设置为 true,将编译器配置为在遇到警告时停止编译。You can also configure the compiler to halt compilation if warnings are encountered by setting the TreatWarningsAsErrors property to true.

若要指定在调用编译进程时使用的自定义命令行参数字符串,请在 CompilerOptions 属性中设置该字符串。To specify a custom command-line arguments string to use when invoking the compilation process, set the string in the CompilerOptions property. 如果在调用编译器进程时需要 Win32 安全令牌,请在 UserToken 属性中指定该令牌。If a Win32 security token is required to invoke the compiler process, specify the token in the UserToken property. 若要在编译的程序集中包括 .NET Framework 资源文件,请将资源文件的名称添加到 EmbeddedResources 属性中。To include .NET Framework resource files in the compiled assembly, add the names of the resource files to the EmbeddedResources property. 若要在另一个程序集中引用 .NET Framework 资源,请将资源文件的名称添加到 LinkedResources 属性中。To reference .NET Framework resources in another assembly, add the names of the resource files to the LinkedResources property. 若要将 Win32 资源文件包含在已编译的程序集中,请在 Win32Resource 属性中指定 Win32 资源文件的名称。To include a Win32 resource file in the compiled assembly, specify the name of the Win32 resource file in the Win32Resource property.

备注

此类包含应用于所有成员的类级别的链接要求和继承要求。This class contains a link demand and an inheritance demand at the class level that applies to all members. 当直接调用方或派生类不具有完全信任权限时,将引发 SecurityExceptionA SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission. 有关安全要求的详细信息,请参阅链接要求继承要求For details about security demands, see Link Demands and Inheritance Demands.

构造函数

CompilerParameters()

初始化 CompilerParameters 类的新实例。Initializes a new instance of the CompilerParameters class.

CompilerParameters(String[])

使用指定的程序集名称初始化 CompilerParameters 类的新实例。Initializes a new instance of the CompilerParameters class using the specified assembly names.

CompilerParameters(String[], String)

使用指定的程序集名称和输出文件名初始化 CompilerParameters 类的新实例。Initializes a new instance of the CompilerParameters class using the specified assembly names and output file name.

CompilerParameters(String[], String, Boolean)

使用指定的程序集名称、输出名和一个指示是否包含调试信息的值来初始化 CompilerParameters 类的新实例。Initializes a new instance of the CompilerParameters class using the specified assembly names, output name, and a value indicating whether to include debug information.

属性

CompilerOptions

获取或设置调用编译器时使用的可选命令行参数。Gets or sets optional command-line arguments to use when invoking the compiler.

CoreAssemblyFileName

获取或设置包含基类类型(如 ObjectStringInt32)的核心或标准程序集的名称。Gets or sets the name of the core or standard assembly that contains basic types such as Object, String, or Int32.

EmbeddedResources

获取要在编译程序集输出时包含的 .NET Framework 资源文件。Gets the .NET Framework resource files to include when compiling the assembly output.

Evidence

指定一个证据对象,该对象表示要授予已编译的程序集的安全策略权限。Specifies an evidence object that represents the security policy permissions to grant the compiled assembly.

GenerateExecutable

获取或设置一个值,该值指示是否生成可执行文件。Gets or sets a value indicating whether to generate an executable.

GenerateInMemory

获取或设置一个值,该值指示是否在内存中生成输出。Gets or sets a value indicating whether to generate the output in memory.

IncludeDebugInformation

获取或设置一个值,该值指示是否在已编译的可执行文件中包含调试信息。Gets or sets a value indicating whether to include debug information in the compiled executable.

LinkedResources

获取当前源中引用的 .NET Framework 资源文件。Gets the .NET Framework resource files that are referenced in the current source.

MainClass

获取或设置主类的名称。Gets or sets the name of the main class.

OutputAssembly

获取或设置输出程序集的名称。Gets or sets the name of the output assembly.

ReferencedAssemblies

获取当前项目所引用的程序集。Gets the assemblies referenced by the current project.

TempFiles

获取或设置包含临时文件的集合。Gets or sets the collection that contains the temporary files.

TreatWarningsAsErrors

获取或设置一个值,该值指示是否将警告视为错误。Gets or sets a value indicating whether to treat warnings as errors.

UserToken

获取或设置在创建编译器进程时使用的用户标记。Gets or sets the user token to use when creating the compiler process.

WarningLevel

获取或设置使编译器中止编译的警告等级。Gets or sets the warning level at which the compiler aborts compilation.

Win32Resource

获取或设置要链接到已编译程序集中的 Win32 资源文件的文件名。Gets or sets the file name of a Win32 resource file to link into the compiled assembly.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于