C# 6.0编译器:可以将csc.exe所在位置 C:Program Files (x86)MSBuild14.0Bin 添加到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:WindowsMicrosoft.NETFrameworkv4.0.30319 或者 C:WindowsMicrosoft.NETFramework64v4.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} {guid:D} {guid:B} {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)