码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-03-21 16:43:45      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:csc.exe   program.cs   


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

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

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

技术分享



3、运行Program.exe文件


技术分享

程序运行界面:

技术分享



4、知识总结


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


MSCorLib.dll is 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 /nostdlib switch. 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参数】

技术分享


4.4、Windows支持的三种Application类型

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






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

标签:csc.exe   program.cs   

原文地址:http://lsieun.blog.51cto.com/9210464/1753476

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!