Converting a ASP.NET MVC 3 Project to MVC 4

asp.net Mvcasp.net Mvc-3asp.net Mvc-4

asp.net Mvc Problem Overview


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 Solutions


Solution 1 - asp.net Mvc

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

  • 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)

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

<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)

This link handles all aspects of the conversion. Refer it as needed.

Solution 2 - asp.net Mvc

Follow the official steps posted here:

Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4

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

Solution 3 - asp.net Mvc

Better yet, use the auto-update tool:

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

Solution 4 - asp.net Mvc

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.

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

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPetrus TheronView Question on Stackoverflow
Solution 1 - asp.net MvcShyjuView Answer on Stackoverflow
Solution 2 - asp.net MvcSethView Answer on Stackoverflow
Solution 3 - asp.net MvcJustinView Answer on Stackoverflow
Solution 4 - asp.net MvcSergioView Answer on Stackoverflow