错误/langversion 选项“6”无效; 必须是 ISO-1、 ISO-2、3、4、5或默认值

我正在瞄准目标。NET 4.6,并利用最新的 C # 版本,将 C # 语言版本更改为6。

然而,在编译过程中我得到了这个错误:

错误/langversion 选项“6”无效; 必须是 ISO-1、 ISO-2、3、4、5或默认值

如果我将 Web.Config 中的 /langversion:6设置更新为5,

  <system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701">

但是如何在不使用低级语言版本的情况下解决这个问题呢?

我正在使用 VisualStudio2015CommunityEdition,并且我还安装了。NET Framework 4.6手动安装,以防 Visual Studio 2015默认情况下没有安装它。

该项目是由 Visual Studio 2015创建的标准 ASP.NET MVC 模板项目。

80511 次浏览

Pay attention to compiler "type" in the Web.Config file, when changing Framework version:

for 4.5 and C#5 -

type="Microsoft.CSharp.CSharpCodeProvider...

for 4.6 and C#6 -

type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

More info in this forum post

I met such behavior if project was not fully upgraded to VS2015. In case if you open solution from 2015 in VS2013 - you will get this error

1.Go to Project and select your Project properties.

2 Select Build and Click Advanced Button.

3.Select Language Version default.

4.Save .

https://youtu.be/IP8feQeWqkk

Update the following NuGet packages (whichever installed) to resolve the problem:

  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  • Microsoft.Net.Compilers

I had similar issue when I was loading application for the first time in visual studio 2019. Updating "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" nuget to later version did the trick for me.

Open NuGet Package Manager console and run this following command

Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r