'Package restore failed. Rolling back package changes

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.



Solution 1:[1]

You can do the following steps:

  1. VS Tools
  2. Options
  3. Nuget Package Manager
  4. General
  5. 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

Solution 2:[2]

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)

Solution 3:[3]

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.

Solution 4:[4]

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>

Solution 5:[5]

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.

Solution 6:[6]

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

Solution 7:[7]

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

Solution 8:[8]

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

Solution 9:[9]

Make sure! you do not use the same name of the project as the Dependency name you are going to install.

Solution 10:[10]

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

Solution 11:[11]

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.

Solution 12:[12]

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.

Solution 13:[13]

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 **

Solution 14:[14]

I am in Visual Studio 2019. I have ContosoUniversity project running in .NET Core 5.

<Project Sdk="Microsoft.NET.Sdk.Web">  
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
   <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.12" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.12">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
</ItemGroup>

<Project>

The package restore error comes while scaffolding because of the conflict in versions. I created a new project from blank and then scaffolded a simple model, and then copied its dependencies version to my existing project and it worked. The above code shows the version specifications that worked for me

Solution 15:[15]

I recently ran into this issue as well while developing a .NET 5 Web API.

The problem stemmed from when I was trying to allow Visual Studio to automatically install the latest version of the NuGet which was Version 6.0.0.

This obviously bombed out as my application was being built in .NET 5 and Microsoft.EntityFrameworkCore 6.0.0 is only compatible with .NET 6 (VS 2022).

To fix, I just needed to verify that the version of EF Core I was installing was compatible with my current .NET version.

Solution 16:[16]

I am using VS2019 and .net5. When I tried to generate controllers and views, Nuget Package suddenly installed 3 packages:

  • EntityFrameworkCore.SQLserver,
  • EntityFrameworkCore.Tools,
  • Microsoft.VisualStudio.web.CodeGeneration.Design

Also update all of them if there is any new version published. But before that I'd have installed the package EntityFrameworkCore. Its version is 5.0.15 as well as SQLserver and Tools(5.0.15).The issue existed only when new version 5.0.16 released. When Scaffolding, VS try to update SQLserver and Tools to 5.0.16 but they were conflicted with EntityFrameworkCore package still in 5.0.15 resulted in:

restored package failed

The solution is uninstall EntityFrameWorkCore package might help you or you can update it manually.

Solution 17:[17]

in my case vs 2022 I update all the packages I already install it and its worked

enter image description here