ARTICLE

How to Upgrade MVC 3 to MVC4

Posted by Amit Patel Articles | ASP.NET MVC with C# July 01, 2012
In this article I will explain how to to upgrade MVC 3 to MVC4.
Reader Level:

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

  1. 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,

  2. In the root Web.config file, update the webPages:Version element to "2.0.0.0" and add a newPreserveLoginUrl key that has the value "true":

    <appSettings>
      
    <add key="webpages:Version" value="2.0.0.0" />
      
    <add key="PreserveLoginUrl" value="true" />
    </
    appSettings>

  3. In Solution Explorer, right-click on the References and select Manage NuGet Packages. Search for Microsoft.AspNet.Mvc and install the Microsoft ASP.NET MVC 4 (RC) package. Click OK.
  4. In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
  5. Locate the ProjectTypeGuids element and replace {E53F8FEA-EAE0-44A6-8774-FFD645390401} with {E3E379DF-F4C6-4180-9B81-6769533ABE47}.
  6. Save the changes, close the project (.csproj) file you were editing, right-click the project, and then select Reload Project.
  7. 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>

Login to add your contents and source code to this article
post comment
     

Visual Studio 2010 SP1 is require for MVC4.

Posted by Amit Patel Jul 02, 2012

No, It works on .NET 4.0 and above.

Posted by Amit Patel Jul 02, 2012

Amit, does MVC 4 uses .NET 4.5?

Posted by Mahesh Chand Jul 02, 2012
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.