Solve the CS1617 error in VS2015 new Web project (C #6,
VS2015 added support for C #6.
Introduce the nuget package in the new Web project templateMicrosoft. CodeDom. Providers. DotNetCompilerPlatform: 1.0.0And add
<system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers> </system.codedom>
To provide Razor C #6.0 support (you can also add the old project to obtain support)
However, after you modify the target framework (for example, upgrade from 4.5 to 4.6), the website will not be able to start and prompt
"/" Indicates a server error in the application. Compilation ErrorNote:An error occurs during compilation of resources required to provide services to this request. Check the following error details and modify the source code as appropriate.
Compiler error message:CS1617: Option "6" does not work on/langversion; must be a ISO-1, ISO-2, 3, 4, 5, or Default
Source error:
|
[No relevant source line] |
Source file:Row:0
Show detailed compiler output:
C: \ Program Files (x86) \ IIS Express> "C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ csc.exe "/t: library/utf8output/R:" C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ Temporary ASP. NET Files \ \... microsoft (R) Visual C # Compiler version 4.6.0081.0for C #5 Copyright (C) Microsoft Corporation. all rights reserved. this compiler is provided as part of the Microsoft (R ). NET Framework, but only supports l Anguage 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 error CS1617: Option "6" is not valid for/langversion; must be a ISO-1, ISO-2, 3, 4, 5, or Default |
|
Check the configuration in web. config and find that the configuration has been automatically modified to (it seems that the cs is not changed to vb, And the vb will be changed together if it is changed to a lower level)
<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"> <providerOption name="CompilerVersion" value="v4.0"/> </compiler> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"> <providerOption name="CompilerVersion" value="v4.0"/> </compiler> </compilers> </system.codedom>
But this is not working properly, and you need to manually change it to the initial result.
Feedback to https://connect.microsoft.com/VisualStudio/feedback/details/1607466