ערוך

שתף באמצעות


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).
ChecksumAlgorithm Optional String parameter.

Specifies the algorithm for calculating the source file checksum stored in the PDB file. The algorithm must be either SHA1 (default) or SHA256. See ChecksumAlgorithm.
CodeAnalysisRuleset Optional String parameter.

Specifies a ruleset file that disables specific diagnostics. See CodeAnalysisRuleset.
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 only want to place the public key in the assembly. If false, specifies that you want a fully signed assembly

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

For more information, see -delaysign (C# compiler options).
Deterministic Optional Boolean parameter.

If true, causes the compiler to output an assembly whose binary content is identical across compilations if inputs are identical.

For more information, see -deterministic (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).
EmbedAllSources Optional Boolean parameter.

Embed all source files in the PDB. For more information, see -embed (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).
ErrorLog Optional String parameter.

Specifies a file to log all compiler and analyzer diagnostics. See ErrorLog.
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).
HighEntropyVA Optional Boolean parameter

Enable high-entropy Address Space Layout Randomization (ASLR). See HighEntropyVA.
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.
Nullable Optional String parameter.

Specifies the nullable context. The argument must be one of enable, disable, warnings, or annotations. See Nullable.
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).
OutputRefAssembly Optional String parameter.

Specifies the name of the output reference assembly file. For more information, see -refout (C# compiler options).
PathMap Optional String parameter.

Specifies how to map physical paths to source path names output by the compiler. See PathMap.
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).
PreferredUILang Optional String parameter.

Specifies the language in which the C# compiler displays output, such as error messages. See PreferredUILang.
PublicSign Optional Boolean parameter.

Publicly sign the output assembly. See PublicSign.
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 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>
RefOnly Optional Boolean parameter.

Produce a reference assembly, instead of a full assembly, as the primary output. See ProduceOnlyReferenceAssembly.
ReportAnalyzer Optional Boolean parameter.

Report additional analyzer information, such as execution time. See ReportAnalyzer.
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 @ (Specify response file).
Sources Optional ITaskItem[] parameter.

Specifies one or more 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).

ToolTaskExtension parameters

This task inherits from the ToolTaskExtension class, which inherits from the ToolTask class, which itself inherits from the Task class. This inheritance chain adds several parameters to the tasks that derive from them.

The following table describes the parameters of the base classes:

Parameter Description
EchoOff Optional bool parameter.

When set to true, this task passes /Q to the cmd.exe command line such that the command line does not get copied to stdout.
EnvironmentVariables Optional String array parameter.

Array of environment variable definitions, separated by semicolons. Each definition should specify an environment variable name and value separated by an equal sign. These variables are passed to the spawned executable in addition to, or selectively overriding, the regular environment block. For example, Variable1=Value1;Variable2=Value2.
ExitCode Optional Int32 output read-only parameter.

Specifies the exit code that is provided by the executed command. If the task logged any errors, but the process had an exit code of 0 (success), this is set to -1.
LogStandardErrorAsError Optional bool parameter.

If true, all messages received on the standard error stream are logged as errors.
StandardErrorImportance Optional String parameter.

Importance with which to log text from the standard error stream.
StandardOutputImportance Optional String parameter.

Importance with which to log text from the standard out stream.
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. Time-out is in milliseconds.
ToolExe Optional string parameter.

Projects may implement this to override a ToolName. Tasks may override this to preserve the ToolName.
ToolPath Optional string parameter.

Specifies the location from where the task loads the underlying executable file. If this parameter is not specified, the task uses the SDK installation path that corresponds to the version of the framework that is running MSBuild.
UseCommandProcessor Optional bool parameter.

When set to true, this task creates a batch file for the command line and executes it by using the command-processor instead of executing the command directly.
YieldDuringToolExecution Optional bool parameter.

When set to true, this task yields the node when its task is executing.

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