Edit

Share via


Compiler.Compile(String[], String[], String, String[], IDictionary) Method

Definition

Compiles the given C# sources to the specified destination file.

public:
 static cli::array <Microsoft::CSharp::CompilerError ^> ^ Compile(cli::array <System::String ^> ^ sourceTexts, cli::array <System::String ^> ^ sourceTextNames, System::String ^ target, cli::array <System::String ^> ^ imports, System::Collections::IDictionary ^ options);
public static Microsoft.CSharp.CompilerError[] Compile (string[] sourceTexts, string[] sourceTextNames, string target, string[] imports, System.Collections.IDictionary options);
static member Compile : string[] * string[] * string * string[] * System.Collections.IDictionary -> Microsoft.CSharp.CompilerError[]
Public Shared Function Compile (sourceTexts As String(), sourceTextNames As String(), target As String, imports As String(), options As IDictionary) As CompilerError()

Parameters

sourceTexts
String[]

An array of type string, each with C# code.

sourceTextNames
String[]

An array of type string that contains the file names for each sourceTexts.

target
String

The output file name. This argument is required.

imports
String[]

An array of type string, with files to reference.

options
IDictionary

An IDictionary of compiler options.

Returns

Returns diagnostic messages as an array of type CompilerError. If the array is empty or all elements are warnings, the compilation succeeded.

Exceptions

sourceTexts is null.

-or-

sourceTextNames is null.

-or-

target is null.

sourceTexts is an empty array.

-or-

sourceTextNames is not the same size as sourceTexts.

Remarks

Each string in the sourceTexts parameter is the equivalent of a single source file. There must be at least one sourceTexts element.

The file names in the sourceTextNames parameter are used for compiler diagnostics and debug information. The array is required, but it can be locally overridden by use of the #line directive. The array must have the same number of elements as the sourceTexts parameter.

The imports parameter is the same as the /reference compiler option. This parameter can be null.

For the options parameter, the key is the short form of the compiler option. The value is the value desired for the option. The options parameter can be null. Some compiler options are not recognized. The following table shows the recognized options and values.

Key Name Usage
addmodule List of modules to include in this assembly. The module names must be separated by the vertical bar or pipe character. Value must be of type String. See -addmodule (C# Compiler Options).
baseaddress Base address for libraries. Value must be of type UInt32. See -baseaddress (C# Compiler Options).
bugreport Produces bug report file. Value must be of type String. See -bugreport (C# Compiler Options).
checked Set default expression evaluation to checked (or unchecked). Value must be of type Boolean. See -checked (C# Compiler Options).
d List of semicolon separated symbols to define. Value must be of type String. See -define (C# Compiler Options).
debug Emit debug information with output. Value must be of type Boolean. Full or pdb-only cannot be specified. See -debug (C# Compiler Options).
doc File name to put XML comments in. Value must be of type String. See -doc (C# Compiler Options).
filealign PE section alignment size. Value must be of type UInt32. See -filealign (C# Compiler Options).
incr Enable incremental rebuild. Value must be of type Boolean.
lib Additional paths to search when locating modules and referenced assemblies. Value must be of type String. See -lib (C# Compiler Options).
linkres Link a managed resource to the assembly. Value must be of type String. See -linkresource (C# Compiler Options).
m Type to search in for the Main method. Value must be of type String. See -main (C# Compiler Options).
nostdlib Do not auto-reference mscorlib.dll. Value must be of type Boolean. See -nostdlib (C# Compiler Options).
nowarn List of semicolon separated warning numbers to not report. Value must be of type String. See -nowarn (C# Compiler Options).
o Enable compiler optimizations. Value must be of type Boolean. See -optimize (C# Compiler Options).
r Referenced assemblies. Value must be of type String. If more than one assembly is specified, the file name must be separated by the vertical bar or pipe character. See -reference (C# Compiler Options).
res Embed a managed resource. Value must be of type String. See -resource (C# Compiler Options).
target Output file target type, one of the following: "library", "exe", "winexe", or "module". Value must be of type String. See -target (C# Compiler Options).
unsafe Allow unsafe constructs. Value must be of type Boolean. See -unsafe (C# Compiler Options).
w Warning level (0-4). Value must be of type String. See -warn (C# Compiler Options).
warnaserror Report warning diagnostics as errors. Value must be of type Boolean. See -warnaserror (C# Compiler Options).
win32icon Win32 icon for auto generated Win32 resource. Value must be of type String. See -win32icon (C# Compiler Options).
win32res Win32 resource file. Value must be of type String. See -win32res (C# Compiler Options).

Applies to

See also