How To Migrate MVC 3 Application To MVC 5


In this article we discuss about how to migrate an MVC 3 application to MVC 5.

Step 1: Open your MVC 3 application in Visual Studio and change the .net framework to 4.5 as MVC 5 runs on this framework.

Project → Properties → Application → Target Framework → 4.5


Note: targetFramework in Web.Config will be changing to 4.5

Step 2: Install Asp.Net MVC 5 version through Package Manager Console.

Run this Command: Install-Package Microsoft.AspNet.Mvc -Version 5.2.3

Nuget Package Manage → Package Manager Console and run above command.


Step 3: Go to Web.Config(root level) and change,

<add key="webpages:Version" value="" />
<add key="webpages:Version" value="" />

Step 4: Check System.Web.Razor, System.Web.Helpers, System.WebPages.Razor versions. These all should be having versions If they don't have Version, Install these packages using Nuget.

Step 5: Now, Build the solution. It this point you may get the following error

Error CS0104 'Compare' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute'

to solve the above issue add using CompareAttribute = System.Web.Mvc.CompareAttribute; in the namespace.

Step 6: Now, Open Web.Config(root level) and change the System.Web.Mvc version to,

  1. <assemblies>  
  2.     <add assembly="System.Web.Abstractions, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  3.     <add assembly="System.Web.Helpers, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  4.     <add assembly="System.Web.Routing, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  5.     <add assembly="System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  6.     <add assembly="System.Web.WebPages, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  7.     <add assembly="System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />   
  8. </assemblies>  
Step 7: Now, Open Web.Config file in View folder. And change the System.Web.WebPages.Razor Version to and System.Web.Mvc version to,
  1. <configSections>  
  2.     <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">  
  3.         <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />  
  4.         <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup>  
  5. </configSections>  
Step 8: If the application has Areas then we have to change the Web.Config files in all the areas as above.

Note: After doing all the above steps, still you have any runtime errors check all the versions of the dlls.
Versions of the respective dlls,



If we run the all the above steps, MVC 3 application will be converted into MVC 5. Then you can use the features of the MVC 5 happily.