How to upgrade from ASP.NET MVC Version 4 to 5?

Recently, I had a requirement to upgrade one of my client’s ASP.NET  MVC web application from version 4 to 5. So, I thought to write the steps to how to upgrade from ASP.NET MVC Version 4 to 5. So that I can also refer this in future and it may help someone else in the community as well.

There is possibility that you may find other latest versions for the packages via Nuget Package Manager at the time of upgrade that may or may not match the versions listed below. But go for the latest ones after looking at their compatibility with MVC 5. Follow the steps below that are same as what I did for current MVC 4 web project:

  • The very important step not to be missed: take backup of the whole solution or use a source control to roll-back to the previous version, if anything goes wrong. Below are the common steps that anyone with this requirement will need and everything should work properly. But it’s better to keep a copy when doing any kind of upgrade.
  • Update the Target Framework for your web project to .NET Framework 4.5 at-least. You can do this by right-click on web project, select properties => Application tab.
  • With freedom to install any package using Nuget Package Manager, you may have different packages installed for your solution. Consider checking the requirements for all the packages whether they are compatible with MVC 5 or not.
  • Right-click on solution => select “Manage Nuget Packages for Solution” option. You can go and try your luck by updating all packages. But I had an issue where I had a package named “Microsoft.AspNet.Web.Helpers.Mvc” installed which is on V 2.0 and it didn’t upgrade to V 3.0 automatically with update all option. Only it’s V 3.0 is compatible with MVC 5. So, if you have got this installed, uninstall it before continuing ahead as we will install in later.
    • Tip: Update the top level packages first and you will find that the dependencies will be update with it automatically. If you go the other way around, it will be very time consuming and may get out of sync. Let the top level package decide, what version of dependencies are required for it to run smoothly. E.g. ASP.NET MVC, Web API 2, Entity Framework, etc.
  • Just to be clear “Micorosft.AspNet.Mvc” package goes from V 4 to 5, “Microsoft.AspNet.Razor” goes from V 2 to 3 and “Microsoft.AspNet.WebPages” goes from V 2 to 3.
  • Next, open top level web.config in your project.
    • Replace application settings value for key “webpages:Version” as:
    • Look for “assemblyBinding” element in file and update oldVersion and newVersion attributes value as below:
      • For name “System.Web.Mvc”, replace 4 with 5.
      • For name “System.Web.WebPages”, replace 2 with 3.
  • Next, open web.config file under Views folder and update the versions in current file:
    • search for “System.Web.WebPages.Razor” and update version to 3 everywhere.
    • search for “System.Web.Mvc” and update version to 5 everywhere.
  • Re-install package “Microsoft.AspNet.Web.Helpers.Mvc” via nuget where Version is 3.0 or up.
  • Unload web project, right click and edit the .csproj file. With this version of asp.net, there is no need of special type of GUID for an MVC project. Now, there’s only asp.net project where you can have MVC, Web-Forms, Web API.
    • Look for the element – “ProjectTypeGuids” that has a guid value which starts with “E3E3” and ends with “E47” and remove that guid from there.  Save the project file and reload this project from solution explorer.
  • Rebuild solution and run your web app with fingers crossed. If everything went well, you will see the startup page of your application in the browser.

Important things to remember is to target .NET Framework 4.5 at-least, update nuget packages by reading the documentation for support with MVC 5, update web.config files in top level and in views folder and  remove the guid from web.config file as described above.

All the above steps helped me to upgrade to MVC 5. Hope, the upgrade process is smooth for you too.

Siddharth Pandey

Siddharth Pandey is a Software Engineer with thorough hands-on commercial experience & exposure to building enterprise applications using Agile methodologies. Siddharth specializes in building, managing on-premise, cloud based real-time standard, single page web applications (SPAs). He has successfully delivered applications in health-care, finance, insurance, e-commerce sectors for major brands in the UK. Other than programming, he also has experience of managing teams, trainer, actively contributing to the IT community by sharing his knowledge using Stack Overflow, personal website & video tutorials.

You may also like...

Advertisment ad adsense adlogger