简体   繁体   English

在 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

After changing my .Net framework from 4.5.2 to 4.5 in VS 2015 Community edition.在 VS 2015 社区版中将我的 .Net 框架从 4.5.2 更改为 4.5 后。 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看起来编译版本不同,但我已经将我的 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;编译器错误消息:CS1617:/langversion 的无效选项“6”; must be ISO-1, ISO-2, 3, 4, 5 or Default必须是 ISO-1、ISO-2、3、4、5 或默认

Source Error:源错误:

[No relevant source lines] [没有相关的源代码行]

Source File: Line: 0源文件:行: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................... 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 Microsoft (R) Visual C# 编译器版本 4.6.0079.0

for C# 5 Copyright (C) Microsoft Corporation.对于 C# 5 版权所有 (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.此编译器作为 Microsoft (R) .NET Framework 的一部分提供,但仅支持最高 C# 5 的语言版本,该版本不再是最新版本。 For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240有关支持更新版本的 C# 编程语言的编译器,请参阅http://go.microsoft.com/fwlink/?LinkID=533240

error CS1617: Invalid option '6' for /langversion;错误 CS1617:/langversion 的无效选项“6”; must be ISO-1, ISO-2, 3, 4, 5 or Default必须是 ISO-1、ISO-2、3、4、5 或默认

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转到每个项目属性 -> Build -> Advance 并将语言版本更改为 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打开启动项目的 web.config(在我的例子中是 MVC)并删除包含自定义编译信息的 codedom 部分

This fix my issue.这解决了我的问题。

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.我怀疑此错误消息来自您的虚拟主机提供商,这意味着他们尚未在其系统上安装最新版本的 .NET Framework,您需要将 web.config 中的 C# 语言编译选项降级回并避免在运行时编译的代码中使用任何 C# 6.0 语言功能。 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 4.5.0 环境中运行 C# 6.0 语言功能会产生什么影响,如果它们依赖于任何新的 CLR 指令。

Update:更新:

Alternatively, ensure you're using the latest version of the Microsoft.Net.Compilers NuGet package, which causes the latest version of csc to be bundled with your project when deployed, so it will have support for C# 6, 7, 8, etc.或者,确保您使用的是最新版本的Microsoft.Net.Compilers NuGet 包,这会导致在部署时将最新版本的csc与您的项目捆绑在一起,因此它将支持 C# 6、7、8 等.

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

This link Helped me 这个链接帮助了我

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 部分这解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET WebAPI项目:HTTP错误403.14-从.net Framework 4.5迁移到4.5.2时禁止 - .NET WebAPI Project: HTTP Error 403.14 - Forbidden when migrating from .net framework 4.5 to 4.5.2 在VS 2015 Community Edition中创建新的.Net Core项目时出现0x80070002错误 - 0x80070002 Error when creating a new .Net Core project in VS 2015 Community Edition Visual Studio 2015:即使从下拉列表中拾取,TargetFramework也不会更改为4.5.2。 恢复至4.5 - Visual studio 2015: TargetFramework does not change to 4.5.2 even if pick up from dropdown. Reverts to 4.5 Windows 10的Xamarin Starter Edition中的.NET Framework 4.5错误 - .NET Framework 4.5 error in Xamarin Starter Edition on Windows 10 从 .Net v4.5 升级到 .Net v4.5.2 后,元素未声明验证错误 - Element is not declared validation error post upgrading from .Net v4.5 to .Net v4.5.2 .net 4.6框架是在适当的升级,然后.net框架4.5如何在vs2015中运行? - .net 4.6 framework is inplace upgrade then how is the .net framework 4.5 works in vs2015? ClickOnce部署要求在安装4.5.2时需要Framework 4.5 - ClickOnce deployment requires Framework 4.5 required when 4.5.2 is installed 如何将.net从4.5.2降级到4.5 - How do I downgrade .net from 4.5.2 to 4.5 如何解决编译目标框架4.5错误? - How to solve compilation target framework 4.5 error? 从 .NET Framework 2.0 迁移到 4.5.2 - Migration from .NET framework 2.0 to 4.5.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM