How to upgrade Asp.Net MVC 4 project to MVC 5

How to upgrade Asp.Net MVC 4 project to MVC 5

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.

ASP.Net MVC 5 bring a host of new features, for example attribute routing, authentication filters etc. Go to this link for more details.

Upgrade to MVC 5 step-by-step guide :

  • First backup your project

    If something goes wrong, you’ll have a working backup.

  • In your global.asax file, change

    to this

  • Check your packages

    Check to see that all your packages , that your project is using, are compatible with MVC 5.

  • Open your project

    This step is self-explanatory, open your project in Visual Studio

  • Remove NuGet Packages

    Remove any of the following ASP.NET NuGet packages that are installed. You can remove these using PMC ( Package Manager Console), in PMC run this following commands :

    Uninstall-Package -Id Microsoft.AspNet.WebPages.Administration
    Uninstall-Package -Id Microsoft-Web-Helpers
    Uninstall-Package -Id Microsoft.AspNet.Mvc.FixedDisplayModes

    * Note that your project might not include all of these packages.

  • Upgrade NuGet Packages

    In the PMC run the following :

    Update-Package *

    This command will update every package, if you wish, you can update packages individually using ID argument.

  • Update Application web.config File

    Find  <runtime>/<assemblyBinding> , and make the following changes :

    for “System.Web.Mvc” change the version from number “” to “” ->

    for “System.Web.Helpers” and “System.Web.Webpages” change the version from “” to “”

      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <!--Two elements removed for Clarity -->
          <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="" newVersion="" />
          <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="" newVersion="" />
          <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="" newVersion="" />
        <!--WebGrease element removed for Clarity -->
  • Update webpages:version

    Locate the <appSettings> section and update the webpages:version from to

        <add key="webpages:Version" value="" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  • Remove trust levels

    Remove all trust levels other than Full

       <!--<trustLevel name="Medium"  policyFile="web_mediumtrust.config"/>-->
  • Update web.config

    Update the web.config files , in your views folder – update all elements that contain

    “System.Web.Mvc” from version “” to “”

      <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <add namespace="System.Web.Mvc" />
          <!--Elements removed for Clarity.-->
          pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
          pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
          userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <add assembly="System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
  • Update Razor elements

    Update all elements that contain “System.Web.WebPages.Razor” from “” to “”

        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />

    * note that if there is “System.Web.WebPages” in this section, update those elements from “” to “”

  • Install Microsoft-Web-Helpers

    Go back to PMC to install Microsoft-Web-Helpers again, run the following :

    Install-Package –Id Microsoft.AspNet.WebHelpers
  • User.IsInRole() method

    If your app use User.IsInRole() method, add the following to the Web.config file :

  • Build and Test

    remove MVC 4 project type GUID from project files , to do that you’ll need to:

    -> open Solution Explorer, right click the project Unload Project.

    -> Right click it again, select Edit YourProject.csproj

    -> find ProjectTypeGuids element, and then remove MVC 4 GUID

    -> save , close project.

    > right click, and select Reload Project


It's not as hard as it looks, just follow simple steps from above and you'll be just fine. If you are searching guide on how to upgrade Asp.Net MVC 3 to MVC 5, you'll need to read this article first and then come back to this one.

Posted by Michael Johnson

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

Related Posts


comments powered by Disqus