如何使命令行C#编译器适用于C#版本> 5?

时间:2018-10-04 13:59:24

标签: c# roslyn

我使用命令行手动调用C#编译器,以编译C#源文件。但是,该编译仍坚持使用C#5。我使用VS2017的路径访问它,因此我希望它也可以在更高版本的C#上使用。设置/langversion属性似乎无法解决问题。

有帮助吗?

PS C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn> csc
Microsoft (R) Visual C# Compiler version 4.7.2558.0 for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

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

..,但仅支持C#5以下的语言版本

1 个答案:

答案 0 :(得分:3)

您的Visual Studio安装或Build Tools安装已过期。

使用当前版本15.8.6,您应该获得以下输出:

PS C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn> .\csc
Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)
Copyright (C) Microsoft Corporation. All rights reserved.

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