突然覺得每次都要開VisualStudio好麻煩,就無聊找了其他編譯方法
在cmd使用csc.exe來編譯。
csc.exe /out:My.exe File.cs
到C:\Windows\Microsoft.NET\Framework\會看到.NET 版本號的資料夾,挑需要的版本點進去會發現裡面有一個 csc.exe,確認有檔案後就開起CMD
輸入:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe
然後就會看到
Microsoft (R) Visual C# Compiler version 4.6.1586.0 for C# 5
由此可知現在的版本號為 Ver 4.6.1586.0 for C# 5.0
使用方式:
1.再根目錄下新增一個文字文件,輸入下列程式碼,另存為HelloWord.cs
using System; namespaceHelloWorld { classProgram { static voidMain(string[] args) { Console.WriteLine("Hello World!"); Console.ReadKey(); } } }
2.在CMD中輸入(要記得檔案位置跟當前位置)
CD C:\Windows\Microsoft.NET\Framework\v4.0.30319 csc.exe /out:HellowWord.exe HellowWord.cs
這樣就完成了,查看更多使用方式(MSDN使用csc.exe建置命令列)
Roslyn C# 編譯器位置?
可是我現在的C#版本明明就是6.0,為什麼版本只到5.0呢
谷鴿半天才知道被藏在這裡了
C:\Program Files (x86)\MSBuild\14.0\Bin
輸入:
C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe
然後就會看到
Microsoft (R) Visual C# Compiler version 1.3.1.60616
版本號變了!!!
使用方式跟前面的一樣
CD C:\Program Files (x86)\MSBuild\14.0\Bin csc.exe /out:HellowWord.exe HellowWord.cs
這樣就可以使用C#6.0的語法了