c#中csc命令

【转】
出处:http://www.cnblogs.com/mq0036/archive/2012/12/25/2832389.html
仅供个人学习使用,如有侵权请及时告知!
1. 配置C#编译器
1).配置C#命令行编译器:
我的电脑 (右键)—〉属性 —〉高级系统设置—〉环境变量 —〉Path —〉新建”;C:\Windows\Microsoft.NET\Framework\v2.0.50727”(Path的最后一个路径虽版本
的改变而改变)。csc.exe(C#命令行编译器)就放在该目录下。通过csc /?来查看所有参数。
step1
step2
step3
2).配置其它.NET命令行工具
我的电脑 —〉高级 —〉环境变量 —〉Path —〉新建”;D:\Program
Files\Microsoft Visual Studio 8\SDK\v2.0\Bin”(Path随安装目录的改变而改变,如
果安装在C:\,则为”;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin”
2. 参数含义
///
命令行示例:
编译 File.cs 以产生 File.exe:
csc File.cs
编译 File.cs 以产生 File.dll:
csc /target:library File.cs
编译 File.cs 并创建 My.exe:
csc /out:My.exe File.cs
通过使用优化和定义 DEBUG 符号,编译当前目录中所有的 C# 文件。输出为 File2.exe:
csc /define:DEBUG /optimize /out:File2.exe *.cs
编译当前目录中所有的 C# 文件,以产生 File2.dll 的调试版本。不显示任何徽标和警告:
csc /target:library /out:File2.dll /warn:0 /nologo /debug *.cs
将当前目录中所有的 C# 文件编译为 Something.xyz(一个 DLL):
csc /target:library /out:Something.xyz *.cs

3.通过csc命令行编译器来编译C#文件,以下为一个例子
1)在D盘下新建一个名为test.txt文本文件,输入以下文本后保存为test.cs文件

//一个简单的C#应用程序.
using System;
class TestApp
{
public static void Main()
{
Console.WriteLine(“Test! 1,2,3”);
Console.ReadKey();
}
}
2)运行 —〉cmd —〉D:\ —〉csc D:\test.cs, 编译成功后在D盘下生成test.exe可执行文件
3)输入test.exe,回车,显示结果(Test! 1,2,3)

4.接下来通过引入System.Windows.Forms命名空间来生成Windows Forms程序,test.cs
修改为如下后再次编译

//一个简单的C#应用程序.
using System;
//一定要加上下面一行
using System.Windows.Forms;

class TestApp
{
public static void Main()
{
Console.WriteLine(“Test! 1,2,3”);
MessageBox.Show(“Hello…”,”Application”);
Console.ReadKey();
}
}
5.使用csc.exe编译多个源文件

//HelloMessage.cs
using System;
using System.Windows.Forms;

class HelloMessage
{
public void Speak()
{
MessageBox.Show(“Hello”);
}
}

//Test.cs
using System;
class TestApp
{
public static void Main()
{
Console.WriteLine(“Testing! 1,2,3”);
HelloMessage h = new HelloMessage();
h.Speak();
}
}
参数/out:编译结果的存放位置和名称

csc/out:e:\a.exe test.cs HelloMessage.cs

或者编译当前目录下的所有cs文件: csc/out:e:\a *cs

至此,配置C#命令行编译器就成功了。

出处:http://developer.51cto.com/art/200908/144575.htm

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值