Linux command
csc 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Compile a C# file
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
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]
说明
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.
参数
- -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.
FAQ
What is the csc command used for?
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.
How do I run a basic csc example?
Run `csc [Program.cs]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -out:_FILE_ do in csc?
Specify output file name.