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] <source files>
csc [options] @<response file>
PARAMETERS
/out:<file>
Specifies the name of the output assembly file.
/target:<target>
Specifies the format of the output file (e.g., exe, library, module, winexe).
/reference:<assembly list> or /r:<assembly list>
References metadata from the specified assembly files.
/debug or /debug+
Emits debugging information into the output.
/optimize or /optimize+
Enables or disables optimizations performed by the compiler.
/warnaserror or /warnaserror+
Treats all warnings as errors, stopping compilation if any warning occurs.
/recurse:<wildcard>
Compiles source files in the current directory and all subdirectories matching the wildcard.
/define:<symbol list> or /d:<symbol list>
Defines conditional compilation symbols.
@<response file>
Reads compiler options from a specified response file.
DESCRIPTION
The csc command, primarily known as the C# compiler, is used to compile C# source code files into executable applications (.exe) or libraries (.dll). It is a crucial component of the .NET framework and Mono project, enabling developers to build applications that run on Linux, Windows, and macOS.
While originally a Windows-centric tool (csc.exe), its availability on Linux via Mono and later .NET Core/.NET 5+ has made it a truly cross-platform compilation utility. It processes .cs files, resolves references, and produces Common Intermediate Language (CIL) code, which is then executed by the Common Language Runtime (CLR). This command is essential for developing C# applications in a Linux environment.
CAVEATS
The csc command directly refers to the Mono/Microsoft C# compiler; it is not a general-purpose Linux utility. It requires a .NET SDK or Mono runtime environment to be installed and configured. In modern .NET development, csc is often invoked indirectly via higher-level commands like dotnet build, which handle project-level settings. The exact set of options may vary slightly between different versions or implementations.
USAGE WITH <B>DOTNET CLI</B>
While csc can be invoked directly, in modern .NET development, it's more common to use the dotnet build or dotnet publish commands. These commands automatically invoke csc with the correct project settings, dependencies, and build configurations defined in .csproj files. Direct csc invocation is often reserved for compiling single files or for specialized scenarios outside of a project context.
MONO VS. <B>.NET CSC</B>
Historically, Mono provided its own C# compiler, often invoked as mcs or via its own csc wrapper. With Microsoft's open-sourcing of .NET and the adoption of Roslyn (Microsoft's C# compiler written in C#), the csc command in modern Linux environments typically refers to the compiler from the official .NET SDK, providing consistent behavior and feature sets across platforms.
HISTORY
The csc command originated with Microsoft's .NET Framework for Windows. Its availability on Linux began with the Mono project, an open-source implementation of .NET. With Microsoft's open-sourcing of .NET Core (later simply .NET), the official csc compiler became a first-class citizen on Linux as part of the .NET SDK. This evolution has focused on modernizing C# language features and ensuring broad cross-platform compatibility.