How To Migrate MVC 3 Application To MVC 5

Introduction
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.7.2 as MVC 5 runs on this framework.


MVC 3 Project Property
Project → Properties → Application → Target Framework → 4.7.2


For Set MVC 5 

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

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

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

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="1.0.0.0" />
to
<add key="webpages:Version" value="3.0.0.0" />
webpages:Version




Step 4: Check System.Web.Razor, System.Web.Helpers, System.WebPages.Razor versions. These all should be having versions 3.0.0.0. If they don't have Version 3.0.0.0, 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 5.2.7.0,

MVC Version Set 5.2.7.0

  1. <assemblies>  
  2.     <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  3.     <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  4.     <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  5.     <add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  6.     <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
  7.     <add assembly="System.Data.Entity, Version=4.0.0.0, 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 3.0.0.0 and System.Web.Mvc version to 5.2.7.0,


  1. <configSections>  
  2.     <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">  
  3.         <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />  
  4.         <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, 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,

System.Web.Mvc5.2.7.0
System.Web.WebPages3.0.0.0
System.Web.Helpers3.0.0.0
System.Web.Razor3.0.0.0
System.WebPages.Razor3.0.0.0


Conclusion
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.

Comments

Popular posts from this blog

Private Chat Using Node js and socket.io with encrypt and decrypt message and insert into mongo db

Populate a drop-down in Vue.js and Asp.net Core from an ajax call