《CLRViaC#》使用CSC.exe进行单文件的编译-创新互联

1、新建一个Program.cs文件,并写入代码

在目录E:\LiuSen\VS\test下,新建一个Program.cs文件,输入以下代码

创新互联凭借专业的设计团队扎实的技术支持、优质高效的服务意识和丰厚的资源优势,提供专业的网站策划、成都网站设计、网站制作、外贸营销网站建设、网站优化、软件开发、网站改版等服务,在成都10多年的网站建设设计经验,为成都上1000家中小型企业策划设计了网站。
using System;

namespace MyConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello world!");
            Console.ReadKey();
        }
    }
}

2、用CSC.exe对Program.cs进行编译

打开Developer Command Prompt for VS2013,并转到目录E:\LiuSen\VS\test下,并使用如下命令进行编译:

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

《CLR Via C#》使用CSC.exe进行单文件的编译

3、运行Program.exe文件

《CLR Via C#》使用CSC.exe进行单文件的编译

程序运行界面:

《CLR Via C#》使用CSC.exe进行单文件的编译

4、知识总结

4.1、/r:MSCorLib.dll可以省略掉

MSCorLib.dllis a special file in that it contains all the core types: Byte, Char, String, Int32, and many more. In fact, these types are so frequently used that the C# compiler automatically references the MSCorLib.dll assembly. In other words, the following command line (with the /r switch omitted) gives the same results as the line shown earlier.【MSCorLib.dll是一个经常被引用的类库,,因此/r MSCorLib.dll参数可以省略】

csc.exe /out:Program.exe /t:exe Program.cs

4.2、/out: Program.exe 和 /t:exe 也可以省略掉

Furthermore, because the /out:Program.exe and the /t:exe command-line switches also match what the C# compiler would choose as defaults, the following command line gives the same results too.

csc.exe Program.cs

4.3、如果不想让MSCorLib.exe参与编译,可以使用/nostdlib

If, for some reason, you really don't want the C# compiler to reference the MSCorLib.dll assembly, you can use the/nostdlibswitch. Microsoft uses this switch when building the MSCorLib.dll assembly itself. For example, the following command line will generate an error when CSC.exe attempts to compile the Program.cs file because the System.Console type is defined in MSCorLib.dll.【如果不想让c# compiler引用MSCore.dll文件,可以加上 /nostdlib参数】

《CLR Via C#》使用CSC.exe进行单文件的编译

4.4、Windows支持的三种Application类型

Windows supportsthree types of applications. To build a console user interface (CUI) application, specify the/t:exeswitch; to build a graphical user interface (GUI) application, specify the/t:winexeswitch; and to build a Windows Store app, specify the/t:appcontainerexeswitch.【在这里,主要注意/t参数的三种类型】

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


网页名称:《CLRViaC#》使用CSC.exe进行单文件的编译-创新互联
URL网址:http://pwwzsj.com/article/dpcigi.html