Unable to update NuGet package "Microsoft ASP.NET MVC" from version 4.0.20710.0 to 5.1.2

16,491

Solution 1

As far as I can tell, upgrading to 4.5.1 did not actually fix the problem. In fact I was able to fix it while leaving the target framework to 4.5.

Here is the black magic I performed that seemed to fix it. First, uninstall the 3 old MVC libraries (as suggested in this comment), reinstall the new ones, rebuild. At least for this part I could do it in the NuGet Manage Packages UI, where the update failed in the same place. At this point NuGet is happy, you can compile, but your app will not actually work.

Next, be sure to follow absolutely every step in the Upgrade ASP.NET 4 document referenced in the other comment. When I accidentally omitted even one step, I'd get strange, non-intuitive errors (obvious in retrospect). For example, you have to update two separate Web.config files, root and one in the Views directory. You have to find the old version numbers and change them manually in that one, where the root Web.config is sometimes automatically fixed for you. Otherwise I'd see scary errors like "inheritance security rules violated by type System.Web.WebPages.Razor.WebPageRazorHost" and so on. I should have copied down each error message for posterity I suppose, but the point is that for every error I'd go back to that upgrade guide, check the steps, realize I missed one, fix and then get a new error until they all went away.

There is good news. In my case at least, despite all the dire warnings that you have to go find incompatibilities, the rest of the app worked as before without any changes.

Solution 2

First change the project framework to 4.5.1

Open the nuget package manager console and

  1. unInstall-Package AspNetMvc
  2. unInstall-Package Microsoft.AspNet.Mvc
  3. Install-Package Microsoft.AspNet.Mvc

This works for me.

Solution 3

MVC 5.1 is build on .NET 4.5.1. That's the first of your problems. You need to change your target framework to ".NET Framework 4.5.1" under the project context menu > Properties.

If that doesn't work, you may want to uninstall the MVC package and reinstall it.

My experience has been that upgrading from major versions can be a pain, and your attention to detail- especially when making changes to web.config- is paramount. You can check the guide on going from 4 to 5 here, and adjust accordingly for 5.1: http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

Depending on the complexity of your project, it can be easier to just transfer your existing code files into a newly created project using the 4.5.1 Visual Studio MVC template.

Share:
16,491
Mike Christensen
Author by

Mike Christensen

Founder and Chief Architect of KitchenPC.com, the world's most powerful recipe search engine. The technology behind KitchenPC is open-source, and available on GitHub.

Updated on June 09, 2022

Comments

  • Mike Christensen
    Mike Christensen almost 2 years

    I have the following out of date package in NuGet:

    enter image description here

    However, when I click on the Update button, I get the following error:

    Error: Updating 'Microsoft.AspNet.Mvc 4.0.20710.0' to 'Microsoft.AspNet.Mvc 5.1.2' failed.

    Unable to find a version of 'AspNetMvc' that is compatible with 'Microsoft.AspNet.Mvc 5.1.2'.

    This happens on both projects that use this package:

    enter image description here

    I'm running on .NET 4.5 framework on both projects. Is there anything I can do to upgrade this package, or is it just not compatible with 4.5, or should I be using a different NuGet package now?

  • Mike Christensen
    Mike Christensen about 10 years
    Great! We just upgraded from .NET 4.0 to 4.5, so I'll try going to 4.5.1 and see if that helps.
  • Mike Christensen
    Mike Christensen about 10 years
    Thanks! Targeting 4.5.1 and removing and re-installing the package fixed the problem. Now, I get runtime errors when I load the site but I guess that's a separate issue. Marking this as the answer.