Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 356
Mike Christensen Avatar asked Apr 24 '14 18:04

Mike Christensen


3 Answers

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.

like image 76
SZL Avatar answered Nov 04 '22 11:11

SZL


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.

like image 28
joelmdev Avatar answered Nov 04 '22 12:11

joelmdev


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.

like image 42
Barnabas Kendall Avatar answered Nov 04 '22 13:11

Barnabas Kendall