csc
Compile C# programs
TLDR
Compile one or more C# files to a CIL executable
Specify the output filename
Compile into a .dll library instead of an executable
Reference another assembly
Embed a resource
Automatically generate XML documentation
Specify an icon
Strongly-name the resulting assembly with a keyfile
SYNOPSIS
csc [options] file1.cs file2.cs ...
PARAMETERS
/out:filename
Specifies the output file name.
/target:exe|winexe|library|module|appcontainerexe|winmdobj|winexe
Specifies the target type: executable, Windows executable, library, or module.
/debug[+|-]
Emits debugging information.
/optimize[+|-]
Enables/disables compiler optimizations.
/reference:assembly1[,assembly2,...]
References one or more assemblies.
/define:symbol1[,symbol2,...]
Defines preprocessor symbols.
/warnaserror[+|-]
Treats all warnings as errors.
/langversion:version
Specifies the language version to use.
/platform:x86|x64|anycpu
Specifies the target platform.
/recurse:*.cs
Include all the C# files in the current directory and subdirectories in the compilation.
DESCRIPTION
The csc command is the command-line compiler for the C# programming language provided by the Mono and .NET frameworks. It takes C# source code files as input and produces executable (.exe) or library (.dll) files.
csc allows you to control various aspects of the compilation process, such as specifying compiler options, defining preprocessor symbols, and linking against external libraries. It's the primary tool for building C# applications from the command line, offering flexibility for automation and integration with build systems. The compiler leverages the Mono or .NET framework for code generation and optimization. csc supports a wide range of C# language features and standards.
CAVEATS
The availability and behavior of specific options may vary slightly depending on the specific Mono or .NET framework version being used.
EXAMPLE USAGE
To compile a simple C# program named 'hello.cs' into an executable:
csc hello.cs
To compile multiple files into a library:
csc /target:library file1.cs file2.cs
EXIT CODES
The csc command returns an exit code of 0 on success, and a non-zero exit code on failure.
HISTORY
The csc command originated with Microsoft's .NET Framework. Mono implemented its own version of csc, named 'mcs', to provide C# compilation capabilities on Linux and other platforms. Both versions have evolved alongside the C# language, adding support for new language features and improving performance.
SEE ALSO
mcs(1)