溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

《CLR Via C#》使用CSC.exe進(jìn)行單文件的編譯

發(fā)布時(shí)間:2020-07-07 09:10:57 來源:網(wǎng)絡(luò) 閱讀:579 作者:lsieun 欄目:編程語言


1、新建一個(gè)Program.cs文件,并寫入代碼

在目錄E:\LiuSen\VS\test下,新建一個(gè)Program.cs文件,輸入以下代碼

using System;

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



2、用CSC.exe對(duì)Program.cs進(jìn)行編譯


打開Developer Command Prompt for VS2013,并轉(zhuǎn)到目錄E:\LiuSen\VS\test下,并使用如下命令進(jìn)行編譯:

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

《CLR Via C#》使用CSC.exe進(jìn)行單文件的編譯



3、運(yùn)行Program.exe文件


《CLR Via C#》使用CSC.exe進(jìn)行單文件的編譯

程序運(yùn)行界面:

《CLR Via C#》使用CSC.exe進(jìn)行單文件的編譯



4、知識(shí)總結(jié)


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是一個(gè)經(jīng)常被引用的類庫,,因此/r MSCorLib.dll參數(shù)可以省略】

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參數(shù)】

《CLR Via C#》使用CSC.exe進(jìn)行單文件的編譯


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參數(shù)的三種類型】






向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI