Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

c# - Error Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...