Linux command
mcs 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Compile C# file
mcs [program.cs]
Output executable
mcs -out:[program.exe] [program.cs]
Build library
mcs -target:library [library.cs]
Reference assembly
mcs -r:[System.dll] [program.cs]
Debug build
mcs -debug [program.cs]
Compile multiple files
mcs [file1.cs] [file2.cs] -out:[program.exe]
说明
mcs is the Mono C# compiler. It compiles C# source code into Common Intermediate Language (CIL) assemblies that run on the Mono or .NET runtime. It supports C# language versions up to C# 7. Options use a colon separator (e.g., `-out:file.exe`, `-target:library`) following Microsoft csc conventions, though the alternate syntax with a space is also accepted in many cases.
参数
- -out:_FILE_
- Output file name.
- -target:_TYPE_
- Output type: exe (console app, default), library (DLL), module, or winexe (GUI app).
- -r:_ASSEMBLY_
- Reference an external assembly.
- -debug
- Emit debugging information.
- -optimize
- Enable compiler optimizations.
- -define:_SYMBOL_
- Define a preprocessor symbol.
- -pkg:_PACKAGE_
- Reference packages registered with pkg-config.
- -recurse:_PATTERN_
- Compile all files matching the pattern recursively.
- -warn:_LEVEL_
- Set warning level (0-4, default 4).
- -warnaserror
- Treat warnings as errors.
- -nowarn:_NUMBERS_
- Suppress specified warning numbers.
- -unsafe
- Enable compilation of unsafe code.
- -checked
- Enable overflow checking.
- -main:_CLASS_
- Specify which class contains the Main entry point.
- -lib:_PATHLIST_
- Comma-separated list of directories to search for assemblies.
- -sdk:_VERSION_
- Specify Base Class Library version (2 or 4, default 4).
- -noconfig
- Disable loading the default compiler configuration.
- -langversion:_VERSION_
- Specify C# language version (e.g., default, latest, ISO-1, ISO-2, 3-7).
- --help
- Display help information.
FAQ
What is the mcs command used for?
mcs is the Mono C# compiler. It compiles C# source code into Common Intermediate Language (CIL) assemblies that run on the Mono or .NET runtime. It supports C# language versions up to C# 7. Options use a colon separator (e.g., `-out:file.exe`, `-target:library`) following Microsoft csc conventions, though the alternate syntax with a space is also accepted in many cases.
How do I run a basic mcs example?
Run `mcs [program.cs]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -out:_FILE_ do in mcs?
Output file name.