C# 6.0 编译器

C# 6.0编译器:可以将csc.exe所在位置 C:\Program Files (x86)\MSBuild\14.0\Bin 添加到Path环境变量。

C:\>csc
Microsoft (R) Visual C# Compiler version 1.0.0.50618
Copyright (C) Microsoft Corporation. All rights reserved.

warning CS2008: No source files specified.
error CS1562: Outputs without source must have the /out option specified

C# 5.0编译器:仍然在原来的位置 C:\Windows\Microsoft.NET\Framework\v4.0.30319 或者 C:\Windows\Microsoft.NET\Framework64\v4.0.30319 


 

例子:用C# 6.0编译器创建一个GUID生成器

设置Path环境变量

按Win+Break键(或者Win+X,Y)打开系统属性窗口,点左侧的“高级系统设置”,在出现的对话框中点“环境变量”按钮,然后点“新建”,输入用户变量Path和csc.exe所在路径。如果已存在“Path”,点编辑,输入csc.exe所在路径,多个路径用英文分号(;)分隔。

源代码 test.cs

using System;

class Program {
    static void Main() {
        var guid = Guid.NewGuid();
        Console.WriteLine($"{guid:N}\r\n{guid:D}\r\n{guid:B}\r\n{guid:P}");
        Console.ReadKey(true);
    }
}

编译成nguid.exe

C:\>csc test.cs /out:nguid.exe

运行nguid

C:\>nguid
b2feb26a275540abbba9df43d6161ad6
b2feb26a-2755-40ab-bba9-df43d6161ad6
{b2feb26a-2755-40ab-bba9-df43d6161ad6}
(b2feb26a-2755-40ab-bba9-df43d6161ad6)

 

posted @ 2015-07-23 10:56  Bob-wei  阅读(4392)  评论(0编辑  收藏  举报