Partager via


Csc Task 

Wraps CSC.exe, which produces executables (.exe), dynamic-link libraries (.dll), or code modules (.netmodule). For more information on 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 (Specify Assembly Reference Locations) (C# Compiler Options).

AddModules

Optional String parameter.

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

AllowUnsafeBlocks

Optional Boolean parameter.

If true, allows code that uses the unsafe keyword to compile. For more information, see /unsafe (Enable Unsafe Mode) (C# Compiler Options).

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 (Specify Base Address of DLL) (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 (Check Integer Arithmetic) (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 (Specify Code Page for Source Code Files) (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 allows source code debugging when the program is started in the debugger but will only display assembler when the running program is attached to the debugger.

This parameter overrides the EmitDebugInformation parameter.

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

DefineConstants

Optional String parameter.

Defines preprocessor symbols. For more information, see /define (Preprocessor Definition) (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 (Delay Sign the Assembly) (C# Compiler Options).

DisabledWarnings

Optional String parameter.

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

DocumentationFile

Optional String parameter.

Processes documentation comments to an XML file. For more information, see /doc (Process Documentation Comments) (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 (Emit Debugging Information) (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 set to prompt, you will receive a prompt if an internal compiler error occurs, giving you the option of sending a bug report electronically to Microsoft. If set to send, a bug report will be sent automatically. If set to none, the error will be reported only in the compiler's text output. Defalut is none. For more information, see /errorreport (Set Error Reporting Behavior) (C# Compiler Options).

FileAlignment

Optional Int32 parameter.

Specifies the size of sections in the output file. For more information, see /filealign (Specify Section Alignment) (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 (Specify Fully Qualified Path in Compiler Output) (C# Compiler Options).

KeyContainer

Optional String parameter.

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

KeyFile

Optional String parameter.

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

LangVersion

Optional String parameter.

Specifies the version of the language to use. For more information, see /langversion (Conformant Syntax) (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 (Link to .NET Framework Resource) (C# Compiler Options).

MainEntryPoint

Optional String parameter.

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

NoConfig

Optional Boolean parameter.

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

NoLogo

Optional Boolean parameter.

If true, suppresses display of compiler banner information. For more information, see /nologo (Suppress Banner Information) (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 (Do Not Import Standard Library) (C# Compiler Options).

Optimize

Optional Boolean parameter.

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

OutputAssembly

Optional String output parameter.

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

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 (Specify Output 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 (Import Metadata) (C# Compiler Options).

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 (Embed Resource File to Output) (C# Compiler Options).

ResponseFiles

Optional String parameter.

Specifies the response file that contains commands for this task. For more information, see @ (Specify Response File) (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 (Specify Output File Format) (C# Compiler Options).

Timeout

Optional Int32 parameter.

Specifies the amount of time, in milliseconds, after which the task executable is terminated. The default value is Int.MaxValue, indicating that there is no time out period.

ToolPath

Optional String parameter.

Specifies the location from where the task will load the underlying executable file (CSC.exe). If this parameter is not specified, the task uses the SDK installation path corresponding to the version of the framework that is running MSBuild.

TreatWarningsAsErrors

Optional Boolean parameter.

If true, treats all warnings as errors. For more information, see /warnaserror (Treat Warnings as Errors) (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 (Display Compiler Messages with UTF-8) (C# Compiler Options).

WarningLevel

Optional Int32 parameter.

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

WarningsAsErrors

Optional String parameter.

Specifies a list of warnings to treat as errors. For more information, see /warnaserror (Treat Warnings as Errors) (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 (Treat Warnings as Errors) (C# Compiler Options).

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

WarningLevel

Optional Int32 parameter.

Sets the appropriate warning level, from 0-4. For more information, see /warn (Specify Warning Level) (C# Compiler Options).

Win32Icon

Optional String parameter.

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

Win32Resources

Optional String parameter.

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

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