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.5 as MVC 5 runs on this framework.
Project → Properties → Application → Target Framework → 4.5
![Project]()
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.
![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" />
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.0.0.0,
- <assemblies>
- <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
- </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.0.0.0,
- <configSections>
- <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">
- <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" />
- <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>
- </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,
![Versions]()
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.