How to Upgrade an ASP.NET MVC 3 Project to ASP.NET MVC 4

How to Upgrade an ASP.NET MVC 3 Project to ASP.NET MVC 4

There are many of benefits of upgrading your project to ASP.NET MVC framework. If you wish to upgrade this is the tutorial for you.

We needed to convert all of our projects from ASP.NET MVC 3 to ASP.NET MVC 4, so we wanted to write a nice blog post that will help others as well. First thing to do when doing any upgrade is to backup your existing project.

There are many of benefits of upgrading your project to ASP.NET MVC framework, but if you switched to Visual Studio 2013 you ll be forced to upgrade. If the ASP.NET MVC is not supported in current Viusal Studio that you are using you will notice that some dll that have yellow icon . This means that dll are missing or not found in your configuration or system. If they exists remove all ASP.NET MVC 3 dll’s from your poject.

The guys at Microsoft says you should create first a new ASP.NET MVC 4 project and copy all the views, controllers, code, and content files from the existing MVC 3 project to the new project and then to update the assembly references in the new project to match any non-MVC template included assembiles you are using.

I think that this is one step overhead and that easiest solutions is to remove dlls from reference and add them from adding reference. Removing following dlls:

  • System.Web.Mvc
  • Microsoft.Web.Infrastructure
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Razor
  • System.Web.Helpers
  • System.Web.WebPages.Deployment

When you are done with adding all the new assembly you will need to make changes on the web config files in the ASP.NET MVC project as well. Remember you will have at least two Web config files inside your project, but you could have even more.

One is in the root folder and second in folder Views. You will need to make changes and update to old assembly versions from 3 to 4 or 5 according to version no.

To manually upgrade an existing ASP.NET MVC 3 application to version 4, do the following:

  • In all Web.config files in the project (there is one in the root of the project, one in the Views folder, and one in the Views folder for each area in your project), replace every instance of the following text (note: System.Web.WebPages, Version=1.0.0.0 is not found in projects created with Visual Studio 2012):
  • System.Web.Mvc, Version=3.0.0.0 System.Web.WebPages, Version=1.0.0.0 System.Web.Helpers, Version=1.0.0.0 System.Web.WebPages.Razor, Version=1.0.0.0
  • with the following corresponding text:
  • System.Web.Mvc, Version=4.0.0.0 System.Web.WebPages, Version=2.0.0.0 System.Web.Helpers, Version=2.0.0.0 System.Web.WebPages.Razor, Version=2.0.0.0
  • In the root Web.config file, update the webPages:Version element to "2.0.0.0" and add a new PreserveLoginUrl key that has the value "true":
  • <appSettings>
  •  <add key="webpages:Version" value="2.0.0.0" />
     <add key="PreserveLoginUrl" value="true" />
  • In Solution Explorer, right-click on the References and select Manage NuGet Packages. In the left pane, select Online\NuGet official package source, then update the following: ASP.NET MVC 4 (Optional) jQuery, jQuery Validation and jQuery UI (Optional) Entity Framework (Optonal) Modernizr
  • In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select EditProjectName.csproj.
  • Locate the ProjectTypeGuids element and replace {E53F8FEA-EAE0-44A6-8774-FFD645390401} with {E3E379DF-F4C6-4180-9B81-6769533ABE47}.
  • Save the changes, close the project (.csproj) file you were editing, right-click the project, and then select Reload Project
  • If the project references any third-party libraries that are compiled using previous versions of ASP.NET MVC, open the root Web.config file and add the following three bindingRedirect elements under the configuration section :
    <configuration> 
  • <!--... elements deleted for clarity ...-->
  •  <runtime>
  •    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  •      <dependentAssembly>
  •        <assemblyIdentity name="System.Web.Helpers"             publicKeyToken="31bf3856ad364e35" />        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>     
  • </dependentAssembly>  
  • <dependentAssembly>
  • <assemblyIdentity name="System.Web.Mvc"    publicKeyToken="31bf3856ad364e35" />
  •  <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0"/>
  • </dependentAssembly>
  • <dependentAssembly>
  •      <assemblyIdentity name="System.Web.WebPages"
  •          publicKeyToken="31bf3856ad364e35" />
  •  <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/></dependentAssembly>
  •   </assemblyBinding>
  • </runtime>
  • </configuration>

Conclusion :

After you finish upgrading to MVC4, why not upgrade to MVC 5? If you wish to do so, please read this article.

Posted by Michael Johnson

Michael Johnson
I am a Digital Marketing expert working for Ingenium on various projects.

Related Posts

Comments

comments powered by Disqus