zoukankan      html  css  js  c++  java
  • VS2015 新Web项目(C#6)出现CS1617错误的解决

    VS2015新增了对C#6的支持.

    在新的Web项目模板中通过引入nuget包Microsoft.CodeDom.Providers.DotNetCompilerPlatform:1.0.0并在web.config中添加

      <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=&quot;Web&quot; /optionInfer+" />
        </compilers>
      </system.codedom>

    来提供Razor的C#6.0支持(旧项目也可以通过自己添加来获得支持)

    但是在当你修改了目标框架(例如从4.5升级到4.6)之后, 网站将会无法开启并提示

    “/”应用程序中的服务器错误。


    编译错误

    说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 

    编译器错误消息: CS1617: 选项“6”对 /langversion 无效;必须是 ISO-1、ISO-2、3、4、5 或 Default

    源错误:

     
    [没有相关的源行]

    源文件:    行: 0 



    C:Program Files (x86)IIS Express> "C:WindowsMicrosoft.NETFrameworkv4.0.30319csc.exe" /t:library /utf8output /R:"C:WindowsMicrosoft.NETFrameworkv4.0.30319Temporary ASP.NET Filesvs...
    
    
    Microsoft (R) Visual C# Compiler version 4.6.0081.0
    
    for C# 5
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    
    
    This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language 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: 选项“6”对 /langversion 无效;必须是 ISO-1、ISO-2、3、4、5 或 Default

    查看web.config中的配置, 发现已被自动修改为(似乎一般是改cs不改vb, 往低了改会连vb一起改)

      <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=&quot;Web&quot; /optionInfer+">
              <providerOption name="CompilerVersion" value="v4.0"/>
          </compiler>
        </compilers>
      </system.codedom>

    而这是无法正常工作的, 需要手动修改为最初的结果


    已反馈至https://connect.microsoft.com/VisualStudio/feedback/details/1607466

    2015/07/31: 微软已确认

  • 相关阅读:
    centos7防火墙那些事
    CentOS7安装mysql数据库
    git回滚到任意版本
    SQL Server查看所有表大小、表行数和占用空间信息
    windows地址转发
    Apache和tomcat服务器使用ajp_proxy模块
    jdk分析工具:jps和jstack
    centos下linux运行asp网站搭建配置-mono+nginx
    reader
    solr课程学习系列-solr服务器配置(2)
  • 原文地址:https://www.cnblogs.com/yyjdelete/p/vs2015_cs1617.html
Copyright © 2011-2022 走看看