20
votes

When I am trying to install any nuget package in VS2017 for asp.net core. it is constantly showing "Package restore failed. Rolling back package changes" for each package.

12
Unless you post the exact error message we can't help you. It usually comes, when you try to add/download a package which is not supported by your platformTseng
"Package restore failed. Rolling back package changes" it's right thereGlyn
Does this answer your question? Error : Package restore failedSayyed Dawood

12 Answers

33
votes

VS Tools -> Options -> Nuget Package Manager ->Package Manager Setting-> General -> Clear All Nuget Cache(s).

OR

You need to change target .net core 1.1 to 2.0, and this is possible if you update your VS 2017 with the latest version(ex. VS 2017 15.3)

enter image description here

13
votes

You Simply need to clear the NuGet Cache. To do this ->

  1. Go to Tools
  2. Options
  3. NuGet Package Manager
  4. General
  5. Clear All NuGet Cache(s)
8
votes

If you are trying update to a dotnet core 2.0 package, you need change the target in .csproject file.

<PropertyGroup>
   <TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
4
votes

enter image description here Try to install the appropriate version of the .net framework which you want to target.

Right click on your project, go to Properties, and then Install Other Frameworks.

This will take you to the TechNet download page for .netCore, download the appropriate SDK version here, install and then restart Visual Studio.

Now go back to Project Properties and pick the new Target Framework version and try again, it should work this time.

3
votes

In my case, i simply needed to update all already installed Nuget packages and then it started working.

2
votes

bring the version of the solution package to 1.1.3 nuget package Version 1.1.3

2
votes

Interestingly, I faced the same problem in .net5 and Visual Studio 2019 v16.9.4, the code generation design package had a version of Microsoft.VisualStudio.Web.CodeGeneration.Design v5.0.2.

After some digging I found out that scaffolding was trying to install a version of Microsoft.EntityFrameworkCore.SqlServer that was older than the one I already depend on. Which was Microsoft.EntityFrameworkCore.SqlServer v5.0.5 so I downgraded its version to v5.0.4 and tried again after clearing nuget cache and it worked! After done scaffolding I then upgraded dependencies back to the desired version that I want.

1
votes

Answer: Add/update nuget package Microsoft.VisualStudio.Web.CodeGeneration.Design

0
votes

Can you please specify which nuget package you are trying to install

As you have said you are getting the error

Package restore failed. Rolling back package changes

once you get this msg open your output window. it will show all the packages it installed and where it has failed and started restoring. From there you will be able to debug it.

For people who are getting error for Microsoft.AspNetCore.All. please go to project>properties>application>target Framework.

The framework should be compatible with Microsoft.AspNetCore.All

0
votes

With VS2019 go to Project > Manage Nuget Packackes... and then check to see if there are any updates for your installed packages, running the updates fixed this for me.

0
votes

For mine it said that i just had to change the version in my .csproj file to "4.5.0.530."

So, I went to the .csproj file, if you don't know how to do so check out this one minute video, and after following the steps, you should come to a page that look something like this.

enter image description here

Change your Version to "4.5.0.530" on the first line (I already did that, but it was originally something like "4.9":

  <PackageReference Include="Xamarin.Forms" Version="4.5.0.530 />

Then you can save the .csproj file and reload the project. Try and re-install the plugin again.

-1
votes

Update Nuget package Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.SqlServer

**it will resolved because while we using scaffolding for new controller then DbContext class object is created that why correct package is required to update for EntityFrameworkCore **