Skip to content
Latchkey

csc Command: Compile C# in CI

csc is the Roslyn C# compiler that turns .cs source into assemblies.

csc is the C# command-line compiler (Roslyn). Most .NET builds go through dotnet build/MSBuild, but csc appears directly in minimal scripts and single-file compiles. Its options use the /flag style rather than the dash style.

Common flags

  • /out:FILE - name the output assembly
  • /target:exe|library|winexe - output kind (/t: short form)
  • /reference:LIB.dll - reference an assembly (/r: short form)
  • /optimize+ - enable optimizations
  • /langversion:latest - select the C# language version
  • /nowarn:CS0168 - suppress a specific warning
  • /warnaserror+ - treat warnings as errors

Example in CI

Compile a single C# program to an optimized executable with strict warnings:

shell
csc /optimize+ /warnaserror+ /langversion:latest /out:app.exe Program.cs

Common errors in CI

  • error CS0246: The type or namespace name 'X' could not be found - missing /reference or using
  • error CS0103: The name 'X' does not exist in the current context
  • error CS5001: Program does not contain a static 'Main' method - no entry point for /target:exe
  • error CS1056: Unexpected character - encoding or stray-character issue in source

Key takeaways

  • csc uses /flag syntax; /target and /reference are the core options.
  • For real projects prefer dotnet build; csc is for one-off compiles.
  • CS0246 means a missing assembly reference or using directive.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →