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



我使用命令行手动调用 C# 编译器以编译 C# 源文件。但是,编译遵循 C# 5。我使用 VS2017 的路径访问它,因此我希望它也适用于更高版本的 C#。设置/langversion属性似乎不起作用。

有什么帮助吗?

PS C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinRoslyn> 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 的语言版本

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

对于当前版本(即 15.8.6(,您应该获得以下输出:

PS C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0BinRoslyn> .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

最新更新