在 VS 2015 社区版中将 .Net 框架从 4.5.2 更改为 4.5 时出现编译错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33317074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compilation Error when change .Net framework from 4.5.2 to 4.5 in VS 2015 Community edition
提问by Neha Jain
After changing my .Net framework from 4.5.2 to 4.5 in VS 2015 Community edition. I am getting following error. Did anyone know what is the issue and how to solve this. Look like compile version is different, but I have already modify my web.config to 4.5
在 VS 2015 社区版中将我的 .Net 框架从 4.5.2 更改为 4.5 后。我收到以下错误。有谁知道是什么问题以及如何解决这个问题。看起来编译版本不同,但我已经将我的 web.config 修改为 4.5
Server Error in '/' Application.
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
Source Error:
[No relevant source lines]
Source File: Line: 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:\Users\admin\AppData\Local\Temp\Temporary ASP.NET Files\root\479d40ee\add72695\assembly\dl3\31bb6ea7\6a8168a8_dae8d001\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS...................
Microsoft (R) Visual C# Compiler version 4.6.0079.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: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
“/”应用程序中的服务器错误。
编译错误说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。
编译器错误消息:CS1617:/langversion 的无效选项“6”;必须是 ISO-1、ISO-2、3、4、5 或默认
源错误:
[没有相关的源代码行]
源文件:行:0
显示详细的编译器输出:
C:\Program Files (x86)\IIS Express> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Users\admin\AppData \Local\Temp\Temporary ASP.NET Files\root\479d40ee\add72695\assembly\dl3\31bb6ea7\6a8168a8_dae8d001\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS .....................
Microsoft (R) Visual C# 编译器版本 4.6.0079.0
对于 C# 5 版权所有 (C) Microsoft Corporation。版权所有。
此编译器作为 Microsoft (R) .NET Framework 的一部分提供,但仅支持最高 C# 5 的语言版本,该版本不再是最新版本。有关支持更新版本的 C# 编程语言的编译器,请参阅 http://go.microsoft.com/fwlink/?LinkID=533240
错误 CS1617:/langversion 的无效选项“6”;必须是 ISO-1、ISO-2、3、4、5 或默认
回答by Neha Jain
I am answering my question just to let other user know what's the solution. After some googling and personal research. So I precisely did two thing.
我回答我的问题只是为了让其他用户知道解决方案是什么。经过一些谷歌搜索和个人研究。所以我恰恰做了两件事。
- Go to each project property -> Build -> Advance and change the language version to C# 5.0
- Open web.config for the startup project (MVC in my case) and remove the codedom section that contain the custom compile information
- 转到每个项目属性 -> Build -> Advance 并将语言版本更改为 C# 5.0
- 打开启动项目的 web.config(在我的例子中是 MVC)并删除包含自定义编译信息的 codedom 部分
This fix my issue.
这解决了我的问题。
回答by Dai
C# in Visual Studio 2015 is C# 6.0, however the error message you're getting is from the ASP.NET Compiler (not the Visual Studio compiler) informing you that C# 6.0 is not available, only C# up-to version 5, so not version 6.
Visual Studio 2015 中的 C# 是 C# 6.0,但是您收到的错误消息来自 ASP.NET 编译器(不是 Visual Studio 编译器),通知您 C# 6.0 不可用,只有 C# 版本 5,所以不版本 6。
I suspect this error message is coming from your webhosting provider, which means they haven't installed the very latest version of the .NET Framework on their systems, you'll need to downgrade your C# language compilation options in your web.config back to what they were before and refrain from using any C# 6.0 language features in runtime-compiled code. I don't know what effect running C# 6.0 language-features in a .NET 4.5.0 environment will have if they rely on any new CLR instructions.
我怀疑此错误消息来自您的虚拟主机提供商,这意味着他们尚未在其系统上安装最新版本的 .NET Framework,您需要将 web.config 中的 C# 语言编译选项降级回并避免在运行时编译的代码中使用任何 C# 6.0 语言功能。我不知道在 .NET 4.5.0 环境中运行 C# 6.0 语言功能会产生什么影响,如果它们依赖于任何新的 CLR 指令。
Update:
更新:
Alternatively, ensure you're using the latest version of the Microsoft.Net.CompilersNuGet package, which causes the latest version of cscto be bundled with your project when deployed, so it will have support for C# 6, 7, 8, etc.
或者,确保您使用的是最新版本的Microsoft.Net.CompilersNuGet 包,这会导致csc在部署时将最新版本与您的项目捆绑在一起,因此它将支持 C# 6、7、8 等。
回答by Daniele D.
I was facing the same building with MSBuild and the following helped me:
我使用 MSBuild 面对同一栋建筑,以下内容对我有帮助:
In Visual Studio > Select your project > Right Click > Properties > Library > Targeting > Change > .Net Framework 4.6
在 Visual Studio > 选择您的项目 > 右键单击 > 属性 > 库 > 目标 > 更改 > .Net Framework 4.6
回答by Muhammad Ahmad
This solution also worked for me. Window 10 Visual studio 2013 .Net framework 4.5
这个解决方案也对我有用。窗口 10 Visual Studio 2013 .Net 框架 4.5
Go to each project property -> Build -> Advance and change the language version to C# 5.0 Open web.config for the startup project (MVC in my case) and remove the codedom section that contain the custom compile information This fix my issue.
转到每个项目属性 -> Build -> Advance 并将语言版本更改为 C# 5.0 打开启动项目的 web.config(在我的情况下为 MVC)并删除包含自定义编译信息的 codedom 部分这解决了我的问题。

