csc

C# compiler from .NET SDK

TLDR

Compile a C# file to executable
$ csc [Program.cs]
Compile multiple files
$ csc [File1.cs] [File2.cs] [File3.cs]
Specify output filename
$ csc -out:[MyApp.exe] [Program.cs]
Create a library (DLL)
$ csc -target:library -out:[MyLib.dll] [Library.cs]
Reference external assemblies
$ csc -reference:[System.Data.dll] [Program.cs]
Compile with optimizations
$ csc -optimize [Program.cs]
Enable all warnings
$ csc -warn:4 [Program.cs]

SYNOPSIS

csc [options] source-files

DESCRIPTION

csc is the C# compiler from the .NET SDK. It compiles C# source files into assemblies (executables or libraries) that run on the .NET runtime. The compiler supports all C# language features and produces MSIL (Microsoft Intermediate Language) code.Modern C# development typically uses the dotnet CLI which invokes csc internally, but direct csc usage is valuable for understanding compilation, scripting builds, or working with legacy projects.The compiler handles syntax checking, type verification, code generation, and optimization. It supports incremental compilation and can produce debug symbols for debugging with Visual Studio or other debuggers.

PARAMETERS

-out:FILE

Specify output file name.
-target:TYPE
Output type: exe, winexe, library, module.
-reference:FILE
Reference an assembly file (can be repeated).
-lib:PATH
Additional directories for assembly references.
-optimize[+|-]
Enable or disable optimizations.
-debug[+|-]
Emit debugging information.
-warn:LEVEL
Warning level (0-4).
-nowarn:WARNINGS
Disable specific warnings.
-define:SYMBOLS
Define conditional compilation symbols.
-doc:FILE
Generate XML documentation file.
-?, -help
Display help information.

INSTALL

sudo apt install chicken-bin
sudo dnf install chicken
sudo pacman -S chicken
sudo apk add chicken
brew install chicken
nix profile install nixpkgs#chicken

CAVEATS

Modern .NET development prefers dotnet build over direct csc invocation. Assembly references must be explicitly specified unlike with project files. Cross-platform .NET Core/5+ uses Roslyn compiler accessed through dotnet CLI.

HISTORY

csc has been the C# compiler since C# 1.0 in 2002. Originally part of .NET Framework, it was reimplemented in C# itself as the Roslyn compiler starting in 2014. The modern csc is part of the .NET SDK and tracks the latest language version (C# 14 with .NET 10, and beyond).

SEE ALSO

dotnet(1), msbuild(1), mono(1), mcs(1)

RESOURCES

Source code · Documentation