.NET程序必须安装.NET Famework才能运行,但我们通常编写.NET程序都是在VSVisual studio)上进行。这就不得不让我们想到如果没有VS是否就不能编写.NET程序了呢?答案是否定的,接下来就让我们对离开VS是如何编译.NET程序一起讨论一下

如何脱离VS编译.NET程序?

首先我们引入一段简单的程序来说明,程序如下:

public sealed class Test

{

    public static void Main()

    {

        System.Console.WriteLine("笑破天学.net");

    }

}

为了能够编译这段代码,我们把它放到Test. cs文件中,执行以下命令:

csc.exe Test.cs

如下图:

 

这时C#编译器生成了一个Test.exe的文件。

C#编译器在编译源文件时,源文件调用了WriteLine方法,编译器需要找到该方法,而这些方法存在于类库中,C#默认在MSCorLib.dll文件中来查找外部类型。而且C#编译器默认生成一个Win32控制台应用程序。因此上述命令是简化的,它的完整形式为:

csc.exe /out:Test.exe /t:exe /r:MSCorLib.dll Test.cs

对于/t:exe表示生成一个Win32控制台应用程序,同样我们也可以生成GUI应用程序(/t:winexe)、类库程序(/t:library)。

 

csc.exe编译器开始编译代码时会默认打开一个csc.rsp文件(查了一些资料称之为“应答文件”),*.rsp文件告诉C#编译器输出的文件名,这就每次编译都指定命令行参数。

具体使用方式为:

csc.exe @test.rsp Test1.cs Test2.cs Test3.cs(@test.rsp为指定打开的应答文件,并且支持多个应答文件)

以下列出v2.0.50727版本的csc.rsp

# This file contains command-line options that the C#

# command line compiler (CSC) will process as part

# of every compilation, unless the "/noconfig" option

# is specified.

# Reference the common Framework libraries

/r:Accessibility.dll

/r:Microsoft.Vsa.dll

/r:System.Configuration.dll

/r:System.Configuration.Install.dll

/r:System.Data.dll

/r:System.Data.OracleClient.dll

/r:System.Data.SqlXml.dll

/r:System.Deployment.dll

/r:System.Design.dll

/r:System.DirectoryServices.dll

/r:System.dll

/r:System.Drawing.Design.dll

/r:System.Drawing.dll

/r:System.EnterpriseServices.dll

/r:System.Management.dll

/r:System.Messaging.dll

/r:System.Runtime.Remoting.dll

/r:System.Runtime.Serialization.Formatters.Soap.dll

/r:System.Security.dll

/r:System.ServiceProcess.dll

/r:System.Transactions.dll

/r:System.Web.dll

/r:System.Web.Mobile.dll

/r:System.Web.RegularExpressions.dll

/r:System.Web.Services.dll

/r:System.Windows.Forms.Dll

/r:System.Xml.dll

posted on 2009-11-27 01:52  pcxpt.exe  阅读(844)  评论(0编辑  收藏  举报