通過C#命令列

來源:互聯網
上載者:User

1.配置C#命令列編譯器:
我的電腦 —〉進階 —〉環境變數 —〉Path
—〉添

加";C:\Windows\Microsoft.NET\Framework\v2.0.50727"(Path的最後一個路徑雖版本

的改變而改變)。csc.exe(C#命令列編譯器)就放在該目錄下。通過csc
/?來查看所有參

數。

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"

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.