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.csCommon 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
/flagsyntax;/targetand/referenceare 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
dotnet build Command: Build .NET in CIdotnet build compiles .NET projects. Reference for -c, -o, -f, --no-restore, -p:Property, --verbosity, and th…
javac Command: Compile Java in CIjavac is the Java compiler. Reference for -d, -cp/-classpath, --release, -source/-target, -Xlint, and the pac…
go build Command: Compile Go in CIgo build compiles Go packages. Reference for -o, -ldflags, -tags, -race, GOOS/GOARCH cross-compilation, and t…