Csc Task

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

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.

The following table describes the parameters of the Csc task.

ParameterDescription
AdditionalLibPathsOptional String[] parameter.

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

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

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

Specifies the application configuration file containing the assembly binding settings.
BaseAddressOptional 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).
CheckForOverflowUnderflowOptional 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).
CodePageOptional Int32 parameter.

Specifies the code page to use for all source code files in the compilation. For more information, see /codepage (C# Compiler Options).
DebugTypeOptional 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).
DefineConstantsOptional String parameter.

Defines preprocessor symbols. For more information, see /define (C# Compiler Options).
DelaySignOptional 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).
DisabledWarningsOptional String parameter.

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

Processes documentation comments to an XML file. For more information, see /doc (C# Compiler Options).
EmitDebugInformationOptional 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).
ErrorReportOptional 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).
FileAlignmentOptional Int32 parameter.

Specifies the size of sections in the output file. For more information, see /filealign (C# Compiler Options).
GenerateFullPathsOptional 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).
KeyContainerOptional String parameter.

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

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

Specifies the version of the language to use. For more information, see /langversion (C# Compiler Options).
LinkResourcesOptional 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).
MainEntryPointOptional String parameter.

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

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

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

If true, suppresses display of compiler banner information. For more information, see /nologo (C# Compiler Options).
NoStandardLibOptional 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).
NoWin32ManifestOptional Boolean parameter.

If true, do not include the default Win32 manifest.
OptimizeOptional Boolean parameter.

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

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

Specifies the debug information file name. The default name is the output file name with a .pdb extension.
PlatformOptional 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).
ReferencesOptional 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>
ResourcesOptional 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).
ResponseFilesOptional String parameter.

Specifies the response file that contains commands for this task. For more information, see @ (Specify Response File).
SourcesOptional ITaskItem[] parameter.

Specifies one or more Visual C# source files.
TargetTypeOptional 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).
TreatWarningsAsErrorsOptional Boolean parameter.

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

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

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

Specifies the warning level for the compiler to display. For more information, see /warn (C# Compiler Options).
WarningsAsErrorsOptional 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.
WarningsNotAsErrorsOptional 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.
Win32IconOptional 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).
Win32ManifestOptional String parameter.

Specifies the Win32 manifest to be included.
Win32ResourceOptional String parameter.

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

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.

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" />  

Task Reference
Tasks

Show: