VS2015 has added support for c#6.
In the new Web project template, by introducing NuGet package microsoft.codedom.providers.dotnetcompilerplatform:1.0.0 and adding in Web. config
<system.codedom> <compilers> <compilerlanguage= "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" /> <compilerlanguage= "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 c#6.0 support for razor (legacy projects can also be added for support)
But after you modify the target frame (for example, from 4.5 to 4.6), the site will not open and prompt
Server error in "/" application. Compile Error Description: An error occurred during compilation of the resource required to provide service to the request. Please check the following specific error details and modify the source code as appropriate.
Compiler Error Message: CS1617: Option "6" is invalid for/langversion; must be ISO-1, ISO-2, 3, 4, 5, or Default
SOURCE Error:
source file: Line: 0
Show verbose 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. Files\vs\ ... Microsoft (R) Visual C # Compiler version 4.6.0081.0for C # 5Copyright (c) Microsoft Corporation. All rights reserved. This compiler was provided as part of the Microsoft (R). NET Framework, and only supports language versions up to C # 5, WHI CH is no longer the latest version. For compilers this support newer versions of the C # programming language, see http://go.microsoft.com/fwlink/? Linkid=533240error CS1617: Option "6" is not valid for/langversion; must be ISO-1, ISO-2, 3, 4, 5, or Default |
|
View the configuration in Web. config, found to have been automatically modified to (seems to be generally changed CS does not change VB, to lower the change will even VB together)
<system.codedom> <compilers> <compilerlanguage= "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"> <provideroptionname= "CompilerVersion"value= "v4.0"/> </compiler> <compilerlanguage= "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+ "> <provideroptionname= "CompilerVersion"value= "v4.0"/> </compiler> </compilers> </system.codedom>
This is not working properly and needs to be manually modified to the original result
Suspect that this should be a bug in VS, who knows the feedback channel's help to mention it.
VS2015 new Web Project (c#6) with CS1617 Error resolution