查看帮助
C:\Users\root\Projects\c#>csc -?
Microsoft(R) Visual C# 编译器版本 4.0.30319.17929
用于 Microsoft(R) .NET Framework 4.5
版权所有 (C) Microsoft Corporation。保留所有权利。
Visual C# 编译器选项
- 输出文件 -
/out: 指定输出文件名(默认值: 包含主类的文件或第一个文件的基名称)
/target:exe 生成控制台可执行文件(默认) (缩写: /t:exe)
/target:winexe 生成 Windows 可执行文件 (缩写: /t:winexe)
/target:library 生成库 (缩写: /t:library)
/target:module 生成能添加到其他程序集的模块 (缩写: /t:module)
/target:appcontainerexe 生成 Appcontainer 可执行文件 (缩写: /t:appcontainerexe)
/target:winmdobj 生成 WinMDExp 使用的 Windows 运行时中间文件 (缩写: /t:winmdobj)
/doc: 要生成的 XML 文档文件
/platform: 限制可以在其上运行此代码的平台: x86、Itanium、x64、arm、anycpu32bitpreferred 或 anycpu。默认值为 anycpu。
- 输入文件 -
/recurse: 根据通配符规范,包括当前目录和子目录下的所有文件
/reference:= 使用给定的别名从指定的程序集文件引用元数据 (缩写: /r)
/reference: 从指定的程序集文件引用元数据 (缩写: /r)
/addmodule: 将指定的模块链接到此程序集中
/link: 嵌入指定的互操作程序集文件中的元数据 (缩写: /l)
- 资源 -
/win32res: 指定 Win32 资源文件(.res)
/win32icon: 对输出使用此图标
/win32manifest: 指定 Win32 清单文件(.xml)
/nowin32manifest 不包括默认 Win32 清单
/resource: 嵌入指定的资源 (缩写: /res)
/linkresource: 将指定的资源链接到此程序集 (缩写: /linkres) 其中 resinfo 的格式是 [,[,public|private]]
- 代码生成 -
/debug[+|-] 发出调试信息
/debug:{full|pdbonly} 指定调试类型(“full”是默认类型,可以将调试程序附加到正在运行的程序)启用优化 (缩写: /o)
- 错误和警告 -
/warnaserror[+|-] 将所有警告报告为错误
/warnaserror[+|-]: 将特定警告报告为错误
/warn: 设置警告等级(0-4) (缩写: /w)
/nowarn: 禁用特定的警告消息
- 语言 -
/checked[+|-] 生成溢出检查
/unsafe[+|-] 允许“不安全”代码
/define: 定义条件编译符号 (缩写: /d)
/langversion: 指定语言版本模式: ISO-1、ISO-2、3、4、5 或 Default
- 安全性 -
/delaysign[+|-] 仅使用强名称密钥的公共部分对程序集进行延迟签名
/keyfile: 指定强名称密钥文件
/keycontainer: 指定强名称密钥容器
/highentropyva[+|-] 启用高平均信息量的 ASLR
- 杂项 -
@ 有关更多选项,请阅读响应文件
/help 显示此用法信息 (缩写: /?)
/nologo 取消编译器版权信息
/noconfig 不要自动包含 CSC.RSP 文件
- 高级 -
/baseaddress: 要生成的库的基址
/bugreport: 创建“Bug 报告”文件
/codepage: 指定打开源文件时要使用的代码页
/utf8output 以 UTF-8 编码格式输出编译器消息
/main: 指定包含入口点的类型(忽略所有其他可能的入口点) (缩写: /m)
/fullpaths 编译器生成完全限定路径
/filealign: 指定用于输出文件节的对齐方式
/pdb: 指定调试信息文件名(默认值: 扩展名为 .pdb的输出文件名)
/errorendlocation 输出每个错误的结束位置的行和列
/preferreduilang 指定首选输出语言名称。
/nostdlib[+|-] 不引用标准库(mscorlib.dll)
/subsystemversion: 指定此程序集的子系统版本
/lib: 指定要在其中搜索引用的附加目录
/errorreport: 指定如何处理内部编译器错误: prompt、send、queue或 none。默认值为 queue。
/appconfig: 指定一个包含程序集绑定设置的应用程序配置文件
/moduleassemblyname: 此模块所属程序集的名称
一个简单的C#程序
// hello.cs
using System;
class TestApp
{
static void Main()
{
Console.WriteLine("Testing! 1, 2, 3");
}
}
C:\Users\root\Projects\c#>csc -t:exe hello.cs
引用外部程序集
// hello.cs
using System;
using System.Windows.Forms;
class TestApp
{
static void Main()
{
Console.WriteLine("Testing! 1, 2, 3");
MessageBox.Show("Hello...");
}
}
C:\Users\root\Projects\c#>csc /r:System.Windows.Forms.dll hello.cs
编译多个源文件
// msg.cs
using System;
using System.Windows.Forms;
class Msg
{
public void Speek()
{
MessageBox.Show("Hello...");
}
}
// hello.cs
using System;
class TestApp
{
static void Main()
{
Console.WriteLine("Testing! 1, 2, 3");
Msg H=new Msg();
H.Speek();
}
}
C:\Users\root\Projects\c#>csc /r:System.Windows.Forms.dll *.cs
使用C#响应文件
// TestApp.rsp
# 外部程序集引用
/r:System.Windows.Forms.dll
# 用于编译的输出和文件 (采用通配符语法)
/target:exe /out:Hello.exe *.cs
csc @TestApp.rsp
引用多个外部程序集
csc /r:System.Windows.Form.dll;System.Drawing.dll *.cs
多个.rsp响应文件
csc /@FirstFile.rsp @SecondFile.rsp @ThirdFile.rsp