Condividi tramite


Csc Task

Wraps CSC.exe, and produces executables (.exe files), dynamic-link libraries (.dll files), or code modules (.netmodule files). For more information about CSC.exe, see C# Compiler Options.

Parameters

The following table describes the parameters of the Csc task.

Parameter

Description

AdditionalLibPaths

Optional String[] parameter.

Specifies additional directories to search for references. For more information, see /lib (C# Compiler Options).

AddModules

Optional String parameter.

Specifies one or more modules to be part of the assembly. For more information, see /addmodule (C# Compiler Options).

AllowUnsafeBlocks

Optional Boolean parameter.

If true, compiles code that uses the unsafe keyword. For more information, see /unsafe (C# Compiler Options).

ApplicationConfiguration

Optional String parameter.

Specifies the application configuration file containing the assembly binding settings.

BaseAddress

Optional String parameter.

Specifies the preferred base address at which to load a DLL. The default base address for a DLL is set by the .NET Framework common language runtime. For more information, see /baseaddress (C# Compiler Options).

CheckForOverflowUnderflow

Optional Boolean parameter.

Specifies whether integer arithmetic that overflows the bounds of the data type causes an exception at run time. For more information, see /checked (C# Compiler Options).

CodePage

Optional Int32 parameter.

Specifies the code page to use for all source code files in the compilation. For more information, see /codepage (C# Compiler Options).

DebugType

Optional String parameter.

Specifies the debug type. DebugType can be full or pdbonly. The default is full, which enables a debugger to be attached to a running program. Specifying pdbonly enables source code debugging when the program is started in the debugger, but only displays assembler when the running program is attached to the debugger.

This parameter overrides the EmitDebugInformation parameter.

For more information, see /debug (C# Compiler Options).

DefineConstants

Optional String parameter.

Defines preprocessor symbols. For more information, see /define (C# Compiler Options).

DelaySign

Optional Boolean parameter.

If true, specifies that you want a fully signed assembly. If false, specifies that you only want to place the public key in the assembly.

This parameter has no effect unless used with either the KeyFile or KeyContainer parameter.

For more information, see /delaysign (C# Compiler Options).

DisabledWarnings

Optional String parameter.

Specifies the list of warnings to be disabled. For more information, see /nowarn (C# Compiler Options).

DocumentationFile

Optional String parameter.

Processes documentation comments to an XML file. For more information, see /doc (C# Compiler Options).

EmitDebugInformation

Optional Boolean parameter.

If true, the task generates debugging information and places it in a program database (.pdb) file. If false, the task emits no debug information. Default is false. For more information, see /debug (C# Compiler Options).

ErrorReport

Optional String parameter.

Provides a convenient way to report a C# internal error to Microsoft. This parameter can have a value of prompt, send, or none. If the parameter is set to prompt, you will receive a prompt when an internal compiler error occurs. The prompt lets you send a bug report electronically to Microsoft. If the parameter is set to send, a bug report is sent automatically. If the parameter is set to none, the error is reported only in the text output of the compiler. Default is none. For more information, see /errorreport (C# Compiler Options).

FileAlignment

Optional Int32 parameter.

Specifies the size of sections in the output file. For more information, see /filealign (C# Compiler Options).

GenerateFullPaths

Optional Boolean parameter.

If true, specifies the absolute path to the file in the compiler output. If false, specifies the name of the file. Default is false. For more information, see /fullpaths (C# Compiler Options).

KeyContainer

Optional String parameter.

Specifies the name of the cryptographic key container. For more information, see /keycontainer (C# Compiler Options).

KeyFile

Optional String parameter.

Specifies the file name containing the cryptographic key. For more information, see /keyfile (C# Compiler Options).

LangVersion

Optional String parameter.

Specifies the version of the language to use. For more information, see /langversion (C# Compiler Options).

LinkResources

Optional ITaskItem[] parameter.

Creates a link to a .NET Framework resource in the output file; the resource file is not placed in the output file.

Items passed into this parameter can have optional metadata entries named LogicalName and Access. LogicalName corresponds to the identifier parameter of the /linkresource switch, and Access corresponds to accessibility-modifier parameter. For more information, see /linkresource (C# Compiler Options).

MainEntryPoint

Optional String parameter.

Specifies the location of the Main method. For more information, see /main (C# Compiler Options).

ModuleAssemblyName

Optional String parameter.

Specifies the name of the assembly that this module will be a part of.

NoConfig

Optional Boolean parameter.

If true, tells the compiler not to compile with the csc.rsp file. For more information, see /noconfig (C# Compiler Options).

NoLogo

Optional Boolean parameter.

If true, suppresses display of compiler banner information. For more information, see /nologo (C# Compiler Options).

NoStandardLib

Optional Boolean parameter.

If true, prevents the import of mscorlib.dll, which defines the entire System namespace. Use this parameter if you want to define or create your own System namespace and objects. For more information, see /nostdlib (C# Compiler Options).

NoWin32Manifest

Optional Boolean parameter.

If true, do not include the default Win32 manifest.

Optimize

Optional Boolean parameter.

If true, enables optimizations. If false, disables optimizations. For more information, see /optimize (C# Compiler Options).

OutputAssembly

Optional String output parameter.

Specifies the name of the output file. For more information, see /out (C# Compiler Options).

PdbFile

Optional String parameter.

Specifies the debug information file name. The default name is the output file name with a .pdb extension.

Platform

Optional String parameter.

Specifies the processor platform to be targeted by the output file. This parameter can have a value of x86, x64, or anycpu. Default is anycpu. For more information, see /platform (C# Compiler Options).

References

Optional ITaskItem[] parameter.

Causes the task to import public type information from the specified items into the current project. For more information, see /reference (C# Compiler Options).

You can specify a Visual C# reference alias in an MSBuild file by adding the metadata Aliases to the original "Reference" item. For example, to set the alias "LS1" in the following CSC command line:

csc /r:LS1=MyCodeLibrary.dll /r:LS2=MyCodeLibrary2.dll *.cs

you would use:

<Reference Include="MyCodeLibrary">
  <Aliases>LS1</Aliases>
</Reference>

Resources

Optional ITaskItem[] parameter.

Embeds a .NET Framework resource into the output file.

Items passed into this parameter can have optional metadata entries named LogicalName and Access. LogicalName corresponds to the identifier parameter of the /resource switch, and Access corresponds to accessibility-modifier parameter. For more information, see /resource (C# Compiler Options).

ResponseFiles

Optional String parameter.

Specifies the response file that contains commands for this task. For more information, see @ (C# Compiler Options).

Sources

Optional ITaskItem[] parameter.

Specifies one or more Visual C# source files.

TargetType

Optional String parameter.

Specifies the file format of the output file. This parameter can have a value of library, which creates a code library, exe, which creates a console application, module, which creates a module, or winexe, which creates a Windows program. The default value is library. For more information, see /target (C# Compiler Options).

TreatWarningsAsErrors

Optional Boolean parameter.

If true, treats all warnings as errors. For more information, see /warnaserror (C# Compiler Options).

UseHostCompilerIfAvailable

Optional Boolean parameter.

Instructs the task to use the in-process compiler object, if available. Used only by Visual Studio.

Utf8Output

Optional Boolean parameter.

Logs compiler output using UTF-8 encoding. For more information, see /utf8output (C# Compiler Options).

WarningLevel

Optional Int32 parameter.

Specifies the warning level for the compiler to display. For more information, see /warn (C# Compiler Options).

WarningsAsErrors

Optional String parameter.

Specifies a list of warnings to treat as errors. For more information, see /warnaserror (C# Compiler Options).

This parameter overrides the TreatWarningsAsErrors parameter.

WarningsNotAsErrors

Optional String parameter.

Specifies a list of warnings that are not treated as errors. For more information, see /warnaserror (C# Compiler Options).

This parameter is only useful if the TreatWarningsAsErrors parameter is set to true.

Win32Icon

Optional String parameter.

Inserts an .ico file in the assembly, which gives the output file the desired appearance in File Explorer. For more information, see /win32icon (C# Compiler Options).

Win32Manifest

Optional String parameter.

Specifies the Win32 manifest to be included.

Win32Resource

Optional String parameter.

Inserts a Win32 resource (.res) file in the output file. For more information, see /win32res (C# Compiler Options).

Remarks

In addition to the parameters listed above, this task inherits parameters from the Microsoft.Build.Tasks.ManagedCompiler class, which inherits from the ToolTaskExtension class, which itself inherits from the ToolTask class. For a list of these additional parameters and their descriptions, see ToolTaskExtension Base Class.

Example

The following example uses the Csc task to compile an executable from the source files in the Compile item collection.

<CSC
    Sources="@(Compile)"
    OutputAssembly="$(AppName).exe"
    EmitDebugInformation="true" />

See Also

Concepts

MSBuild Tasks

Other Resources

MSBuild Task Reference