关于 Visual Studio:在 VS 2015 社区版中将 .Net 框架从 4.5.2 更改为 4.5 时出现编译错误
Compilation Error when change .Net framework from 4.5.2 to 4.5 in VS 2015 Community edition
在 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 DefaultSource 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
oot\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=533240error CS1617: Invalid option '6' for /langversion; must be ISO-1,
ISO-2, 3, 4, 5 or Default
相关讨论
- Microsoft 链接将我重定向到 dotnet / roslyn GitHub 页面。我不知道它是什么
- roslyn 是一个新的 .Net 编译器,它是跨平台的(除了 windows 还可以在 Mac 和 linux 上工作)
我回答我的问题只是为了让其他用户知道解决方案是什么。经过一些谷歌搜索和个人研究。所以我正好做了两件事。
-
转到每个项目属性 -> 构建 -> 高级并更改
语言版本到 C# 5.0 -
打开启动项目的 web.config(在我的例子中是 MVC)并删除
包含自定义编译信息的 codedom 部分
这解决了我的问题。
相关讨论
- 我在 Visual Studio 2015 试用版中启动的 MVC 项目中遇到了这个问题。此修复程序为我解决了它。
- 对我没有帮助,但它立即帮助将 web.config 中的 langversion 从 6 更改为 5:stackoverflow.com/questions/32380064/...
- 链接已失效。
- 糟糕的解决方案 🙁 项目正在使用 C# 6 => 你的解决方案 "downgrade to C#5"
Visual Studio 2015 中的 C# 是 C# 6.0,但是您收到的错误消息来自 ASP.NET 编译器(不是 Visual Studio 编译器),通知您 C# 6.0 不可用,只有 C# 最新版本5,所以不是版本 6。
我怀疑此错误消息来自您的虚拟主机提供商,这意味着他们尚未在其系统上安装最新版本的 .NET Framework,您需要在您的系统中降级 C# 语言编译选项web.config 恢复到以前的状态,并避免在运行时编译的代码中使用任何 C# 6.0 语言功能。如果依赖任何新的 CLR 指令,我不知道在 .NET 4.5.0 环境中运行 C# 6.0 语言功能会有什么影响。
更新:
或者,确保您使用的是最新版本的 Microsoft.Net.Compilers NuGet 包,这会导致在部署时将最新版本的 csc 与您的项目捆绑在一起,因此它将支持 C# 6、7 , 8 等
相关讨论
- 几分钟前它还在工作。我只是在 VS 2015 中将版本从 4.5.2 更改为 4.5,我开始收到此错误
这个解决方案也对我有用。
窗口 10
视觉工作室 2013
.Net 框架 4.5
转到每个项目属性 -> 构建 -> 高级并将语言版本更改为 C# 5.0
打开启动项目的 web.config(在我的例子中是 MVC)并删除包含自定义编译信息的 codedom 部分
这解决了我的问题。
我正面临着使用 MSBuild 的同一栋建筑,以下帮助了我:
在 Visual Studio > 选择您的项目 > 右键单击?? > 属性 > 库 > 目标 > 更改 > .Net Framework 4.6
这个链接帮助了我