asp.net-mvc 将 ASP.NET MVC 3 项目转换为 MVC 4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8853330/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 01:41:20  来源:igfitidea点击:

Converting a ASP.NET MVC 3 Project to MVC 4

asp.net-mvcasp.net-mvc-3asp.net-mvc-4

提问by Petrus Theron

What steps should I take to safely upgrade an existing ASP.NET MVC 3 project to the latest ASP.NET MVC 4 Developer Preview?

我应该采取哪些步骤来安全地将现有的 ASP.NET MVC 3 项目升级到最新的 ASP.NET MVC 4开发人员预览版

采纳答案by Shyju

The major change is to upgrade the relevant references to the latest version (4.0 /2.0). You need to update your web config files to upgrade the version of the following namespaces

主要变化是将相关参考升级到最新版本(4.0/2.0)。您需要更新您的 Web 配置文件以升级以下命名空间的版本

  • System.Web.Mvc ( Change to 4.0.0.0)
  • System.Web.Webpages (Change to 2.0.0.0)
  • System.Web.Helpers (Change to 2.0.0.0)
  • System.Web.WebPages.Razor (Change to 2.0.0.0)
  • System.Web.Mvc(更改为 4.0.0.0)
  • System.Web.Webpages(更改为 2.0.0.0)
  • System.Web.Helpers(更改为 2.0.0.0)
  • System.Web.WebPages.Razor(更改为 2.0.0.0)

Also you need to update the root level web config file to have these appsettings entries

您还需要更新根级别的 Web 配置文件以包含这些 appsettings 条目

<appSettings>
  <add key="webpages:Version" value="2.0.0.0" />
  <add key="PreserveLoginUrl" value="true" />
</appSettings>

Then you need to update the DLLs referenced in the project. Remove the existing MVC3 dll reference and add MVC4 (use nuget package manager to do this)

然后您需要更新项目中引用的 DLL。删除现有的 MVC3 dll 引用并添加 MVC4(使用 nuget 包管理器执行此操作)

This linkhandles all aspects of the conversion. Refer it as needed.

链接处理转换的所有方面。根据需要参考它。

回答by Seth

Follow the official steps posted here:

按照此处发布的官方步骤操作:

http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806

http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806

Note: These steps cover the official release--not the developer preview.

注意:这些步骤涵盖了正式版本——而不是开发者预览版。

回答by Justin

Better yet, use the auto-update tool:

更好的是,使用自动更新工具:

https://www.nuget.org/packages/UpgradeMvc3ToMvc4

https://www.nuget.org/packages/UpgradeMvc3ToMvc4

回答by Sergio

Your best bet it's installing the MVC4 from the platform installer. Then follow the steps on the official asp.net/mvc/mvc4 page. If you follow (only) the Shyju instructions It wouldn't work.

您最好的选择是从平台安装程序安装 MVC4。然后按照官方asp.net/mvc/mvc4页面上的步骤操作。如果您(仅)按照 Shyju 说明进行操作,则行不通。

When you end with the official instructions, look on your Views directory, and you may find another web.config with another reference to the MVC assembly and several others for razor. You also want to change the versions of this lines. Basically replace every 3.0.0.0 you find for 4.0.0.0 and 1.0.0.0 for 2.0.0.0

当您以官方说明结束时,查看您的 Views 目录,您可能会发现另一个 web.config,其中包含对 MVC 程序集的另一个引用以及其他几个用于 razor 的引用。您还想更改此行的版本。基本上将您找到的每个 3.0.0.0 替换为 4.0.0.0 并将 1.0.0.0 替换为 2.0.0.0

IF YOU DON'T MAKE THIS LAST CHANGE, YOU MAY END WITH THE ERROR ON THE FOLLOWING QUESTION

如果您不进行最后一次更改,您可能会以以下问题中的错误结束

Look for included dll's and make sure they're for the correct versions.

查找包含的 dll 并确保它们适用于正确的版本。