简体   繁体   English

如何将目标框架正确更改为.NET 4.0

[英]How to properly change target framework to .NET 4.0

I built an application with target framework .NET 4.6 using MVC 5 and Entity Framework 6 using Visual Studio 2017 on my Windows 7 machine. 我在Windows 7计算机上使用Visual Studio 2017使用MVC 5和Entity Framework 6构建了具有目标框架.NET 4.6的应用程序。 I'm now being told that I should have built the application to target .NET 4.0 because the production environment only has 4.0 installed. 现在,我被告知我应该以.NET 4.0为目标构建该应用程序,因为生产环境仅安装了4.0。 So I changed the target framework to 4.0 but now the application will not build on my machine. 因此,我将目标框架更改为4.0,但现在该应用程序将无法在我的计算机上构建。

I'm guessing I also need to downgrade MVC and EF. 我猜我还需要降级MVC和EF。 How is the proper way of doing this? 如何做到这一点的正确方法?

And which versions of MVC and EF should I install? 我应该安装哪个版本的MVC和EF?

Do I need to make any manual changes to web.config? 我是否需要对web.config进行任何手动更改?

There is no "proper" way, you have 3 options, in my favorite order: 没有“适当”的方式,您有3个选项,以我最喜欢的顺序排列:

  • Update the server/install .net 4.5. 更新服务器/安装.net 4.5。
  • Start over in a new project and make sure you target version 4.0: you can copy most of your source files. 重新开始一个新项目,并确保您以4.0版为目标:您可以复制大多数源文件。 You'll probably get some compiler errors, but usually they are easily fixed. 您可能会遇到一些编译器错误,但是通常它们很容易修复。 This way you'll have the benifit that the used template matches the framework and packages version(s). 这样,您将获得所使用的模板与框架和软件包版本匹配的好处。
  • Re-target the used framework in the project properties and replace the packages which are installed and hope for the best (sometimes you need other packages). 在项目属性中重新定位使用的框架,并替换已安装的软件包并希望获得最佳软件包(有时您需要其他软件包)。 Hopefully you used the package manager to install those packages. 希望您使用软件包管理器来安装那些软件包。 Maybe the update-packages command helps, but be sure to backup your project first. 也许update-packages命令会有所帮助,但是请务必先备份您的项目。 Some packages become obsolete after time, some are renamed. 有些软件包会在一段时间后过时,有些会被重命名。 This is what will cause issues. 这将导致问题。 Also, some of the Methods/API calls will be different, so some rework will be needed. 此外,某些方法/ API调用将有所不同,因此需要进行一些重做。

As for the rest of your questions: 至于其余的问题:

I'm guessing I also need to downgrade MVC and EF. 我猜我还需要降级MVC和EF。 How is the proper way of doing this? 如何做到这一点的正确方法?

Use the nuget package manager

And which versions of MVC and EF should I install? 我应该安装哪个版本的MVC和EF?

The nuget package manager will fix this for you.

Do I need to make any manual changes to web.config? 我是否需要对web.config进行任何手动更改?

Sometimes: yes.

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM