您的位置:首页 > 编程语言 > C#

Cmd命令行编译c#文件

2015-11-27 20:37 393 查看
使用命令行编译C#文件的方法:

首先,在系统变量的Path变量中添加csc.exe文件路径

路径大概是这个样子:C:\Windows\Microsoft.NET\Framework64\v4.0.30319; (.net版本也许不同)



在cmd中输入csc.exe验证是否成功。

cs文件生成exe文件:(若要编译生成EXE文件则源文件中需包含main 方法)

csc /out:file.exe file.cs //使用 /out 指定输出的文件

如果编译的stu.cs 和 file.cs中都有main方法:

csc stu.cs file.cs /main:stu //使用 /main 指定main方法的位置

cs文件生成dll文件:
csc /target:library file.cs 生成file.dll文件 //使用 /target 指定文件的输出格式

其他target类型:

/target:exe 创建一个可执行程序

/target:module 创建一个模块

/target:winexe 创建一个Windows程序

cs文件和同目录下的dll文件一起编译生成dll文件:

csc /target:library stu.cs /r:file.cs 生成stu.dll文件 // /reference:<文件列表> 从指定的程序集文件引用元数据 (缩写: /r)

csc /r:system.dll;mylibrary.dll file.cs //编译文件,引用程序中使用的文件

编译指定目录及其子目录下的所有源代码文件:

csc /target:library /out:file.dll /recurse: dir\ *.cs

附csc编译C#代码时使用的参数和开关选项:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: