I am trying to target .NET 4.6 and also take advantage of the latest C# version by changing the C# language version to 6.
However during compilation I got this error:
Error Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
If I update the /langversion:6
in Web.Config setting to 5 it works,
<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">
But how do I resolve this without resorting to lower language version?
I am using Visual Studio 2015 Community Edition, and I have also installed .NET Framework 4.6 manually just in case it was not installed by default by Visual Studio 2015.
The project is a standard ASP.NET MVC template project created by Visual Studio 2015.
答案 0 :(得分:84)
注意编译器&#34;输入&#34;在Web.Config
文件中,更改Framework版本时:
表示4.5和C#5 -
type="Microsoft.CSharp.CSharpCodeProvider...
表示4.6和C#6 -
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
答案 1 :(得分:22)
更新以下NuGet软件包(以安装者为准)解决问题:
答案 2 :(得分:9)
答案 3 :(得分:3)
如果项目未完全升级到VS2015,我遇到了这样的行为。如果您在2015年在VS2013中打开解决方案 - 您将收到此错误
答案 4 :(得分:2)
打开NuGet软件包管理器控制台并运行以下命令
更新包Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
答案 5 :(得分:0)
查看 ASP.NET strange compilation error! 的答案。
将您的C#语言降级为5只会掩盖问题,只要有人使用C#6功能,您的网站/项目就会中断,您仍然会花时间再次修复它。尝试链接中的解决方案。
答案 6 :(得分:0)
当我第一次在Visual Studio 2019中加载应用程序时,我遇到了类似的问题。将“ Microsoft.CodeDom.Providers.DotNetCompilerPlatform” nuget更新到更高版本对我来说很成功。