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 [-option...] source-files
PARAMETERS
-out:
Name of output file or assembly
-target:
Target type: exe, winexe, library, module, winmdobj
-reference:
Reference metadata from assemblies
-debug[+|-]
Emit debugging information
-optimize[+|-] or -o[+|-]
Enable optimizations
-define:
Define conditional compilation symbols
-unsafe[+|-]
Allow unsafe code blocks
-platform:
Target platform: anycpu, anycpu32bitpreferred, x86, x64, arm, arm64
-warn:
Set warning level (0-4)
-recurse:
Recursively include source files matching pattern
DESCRIPTION
csc is the official command-line compiler for the C# programming language in the .NET ecosystem. It translates C# source files (.cs) into executable assemblies (.exe or .dll), modules, or other targets. On Linux, it is available via the Mono framework or the .NET SDK (formerly .NET Core).
Primarily used for compiling single files or small projects, csc supports advanced features like optimization, debugging symbols, assembly references, conditional compilation, and unsafe code. It emits Microsoft Intermediate Language (MSIL) code, which is JIT-compiled at runtime by the .NET runtime.
Basic usage: csc hello.cs produces hello.exe. For libraries: csc -target:library -out:mylib.dll *.cs. It integrates with build tools like MSBuild but is ideal for quick compilations or scripts.
Options mimic Windows behavior for cross-platform consistency. Always consult man csc or Microsoft docs for full details, as options evolve with .NET versions. Requires dotnet-sdk or Mono installed.
CAVEATS
Not installed by default; install via dotnet-sdk or Mono. Prefer dotnet build for complex projects. Hundreds of options exist—use man csc or csc -help. Version-specific behaviors apply.
RESPONSE FILES
Use @filename to read options from a text file, useful for long argument lists.
Example: csc @build.rsp hello.cs
EMBEDDED RESOURCES
-resource:
HISTORY
Developed by Microsoft in 2001 for .NET Framework. Ported to Linux by Mono project (2004) for cross-platform use. Official Linux support via .NET Core 1.0 (2016), now .NET 8+ with improved performance and AOT compilation.


