29

There is a (non-Microsoft) NuGet package that allows upgrading the Mvc3 to Mvc4.

There is a (Microsoft) article that explains how to manually migrate from Mvc3 to Mvc4. We can read from that article, by ex:

Locate the ProjectTypeGuids element and replace {E53F8FEA-EAE0-44A6-8774-FFD645390401} with {E3E379DF-F4C6-4180-9B81-6769533ABE47}.

Now, is there something similar that allows migrating from MVC3 to MVC5?

Is there sufficient to migrate first from 3 to 4, and then re-target the framework version (to 4.5) and install the official MVC nu-get?

serhio
  • 28,010
  • 62
  • 221
  • 374

2 Answers2

37

Due to the installation of VS2015 I had to convert my applications from MVC3 on MVC5. I've done this with success :). I hope that the following description will help someone in a similar issue:

1) Change .Net Framework to 4.5

Project -> Properties -> Application -> Target Framework -> 4.5

2) Install from Package Manager Console:

Install-Package Microsoft.AspNet.Mvc -Version 5.2.3

3) There is a line in web.config that is:

<add key="webpages:Version" value="1.0.0.0" />

Changed it to the version of system.web.webpages.dll in your bin folder:

<add key="webpages:Version" value="3.0.0.0" />

4) If your project uses the EntityFramework you have to upgrade it to version 5.x or higher and set dll references to

....\net45\EntityFramework.dll
....\net45\EntityFramework.SqlServer.dll

5) To solve problems like:

Error   CS0104  'Compare' is an ambiguous reference between 'System.ComponentModel.DataAnnotations.CompareAttribute' and 'System.Web.Mvc.CompareAttribute'

you can add:

using CompareAttribute = System.Web.Mvc.CompareAttribute;

6) You will probably have to change additional definitions in the web.config and the Views\web.config and find and replace text as shown below:

System.Web.Mvc, System.Web.Mvc.*, System.Web.Razor, System.Web.WebPages.Razor change from 3.0.0.0 to 5.0.0.0

System.Web.WebPages, System.Web.WebPages.* change from 1.0.0.0 to 3.0.0.0

7) Now, optionally, you can do a little overview of MVC views and simplify your code with Razor conditional attributes. There was a breaking change in the way Razor behaves.
(velsietis comment)

That's all :)

Jerzy Gebler
  • 929
  • 9
  • 13
  • 1
    As this is one of the top search results for converting MVC 3 to 5, can I suggest you add this step to your answer: **7)** Check through your Views for any usages of boolean (or empty string) values inside html attributes. There was a breaking change in the way Razor behaves [reference](https://blog.craigtp.co.uk/Post/2013/02/17/Razor%27s_Conditional_Attributes_Bit_Me!) – velsietis Mar 18 '19 at 21:31
8

As an answer that someone suggested, then for a unknow cause removed, I will add this article reference for the question above:

How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2

serhio
  • 28,010
  • 62
  • 221
  • 374
  • Mine is a vb.net project and I don't see this line WebApiConfig.Register(GlobalConfiguration.Configuration) in Global.asax or Global.asax.vb. Isn't there an official "how to" form Microsoft somewhere? I find it surprising that Microsoft created these incompatible versions without providing a tool to help upgrade. – Allen King Jul 16 '14 at 14:53
  • 3
    I'm also surprised that Microsoft doesn't seem to have any recommendation for people who want to go from MVC3 to MVC5. a) Either directly to MVC5, or b) through MVC4. – Michael R Jul 18 '14 at 17:43