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.
-
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 platform – Tseng Aug 27 '17 at 16:11
-
6"Package restore failed. Rolling back package changes" it's right there – Glyn May 30 '18 at 13:28
-
Does this answer your question? [Error : Package restore failed](https://stackoverflow.com/questions/44509694/error-package-restore-failed) – Sayyed Dawood Apr 27 '21 at 22:46
25 Answers
You can do the following steps:
- VS Tools
- Options
- Nuget Package Manager
- 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)

- 2,824
- 1
- 30
- 45
-
This doesn't solve my problem. Mine still fails after doing this. – Alexander Ryan Baggett Apr 04 '22 at 17:42
-
-
You Simply need to clear the NuGet Cache. To do this ->
- Go to Tools
- Options
- NuGet Package Manager
- General
- Clear All NuGet Cache(s)
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,495
- 1
- 15
- 16
-
1This was the solution in my case as well- I had to downgrade all my EF Core NuGet packages to v5.0.4 in a related project that the UI project had a dependency on. Then everything scaffolded correctly. – daniel_sweetser Sep 24 '21 at 17:04
-
2I have downgraded 'Microsoft.EntityFrameworkCore.SqlServer' NuGet package from V5.0.13 to V5.0.12 and now i can generate razor pages. Thanks... – Sayed Mahmoud Jan 31 '22 at 23:20
-
This is still happening as of 3/13/22 with .NET 6. For me, downgrading Microsoft.EntityFrameworkCore.SqlServer from 6.0.3 to 6.0.2 allowed me to scaffold a new controller. – Naughton Mar 14 '22 at 04:11
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>

- 437
- 2
- 10
-
This solved the problem for me - was targeting Core 1.1, needed to change build target to 2.0 - thanks. – jlmt Oct 10 '17 at 18:32
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.

- 12,569
- 2
- 33
- 48

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

- 1,096
- 10
- 20
-
1In my case, VS2019 wants to install Microsoft.EntityFrameworkCore.SqlServer v5.0.11, but I already installed and had it with v5.0.7. So after I update it along with other packages to v5.0.11 and Clear All NuGet Cache(s) it works for me. – Mahdi Abyaznezhad Nov 01 '21 at 09:27
I just install these packages and it worked
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.EntityFrameworkCore.Tools
- Microsoft.VisualStudio.Web.CodeGeneration.Design
The version of the packages you install must be the same as your .Net or .NetCore version.

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

- 67
- 1
- 3
-
This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30286333) – Bracken Nov 12 '21 at 15:36
-
1This is true, if the pckage you are trying to install and your project name are same, you will get the same error. Package restore failed. Rolling back package changes. Cycle detected. – Sibeesh Venu Sep 03 '22 at 13:55
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.

- 2,324
- 26
- 22
- 31

- 11
- 1
In my case, I named the project same as the plugin that i wanted to install cause this error.
for example:
My project is named ScottPlot
, and error occur when i want to install the nuget package ScottPlot
Rename the project or recreate with different name will solve this error!

- 395
- 3
- 11
This error happened in my dotnet 0.7 C# project. after trying out above solutions. it didn't resolve my case.
Then I followed the below steps, and the problem was solved:
1- I renamed my existing [ApplicationDBContext] into the solution to another name.
2- I uninstalled two packages using Nuget package manager.
Microsoft.VisualStudio.Web.CodeGeneration.Design
and
Microsoft.VisualStudio.Web.CodeGeneration.Contracts
Eventually I called [add new]-> [New scaffolded Item] in the pop-up screen, I selected [Identity] from left panel, then I hit [New] button
It worked fine and I was able to collect all identity pages.

- 155
- 1
- 8
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

- 486
- 5
- 17
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.

- 1,010
- 3
- 17
- 34
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.
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.

- 71
- 1
- 5
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 **
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

- 51
- 3
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.

- 76
- 8
in my case vs 2022 I update all the packages I already install it and its worked
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 17 '22 at 05:31
This was happening to me, I had to go to my .csproj file and directly reference the changes i want to make in there. For example:
FROM
<PackageReference Include="Amazon.Extensions.CognitoAuthentication" Version="2.2.2" />
TO
<PackageReference Include="Amazon.Extensions.CognitoAuthentication" Version="2.2.3" />
Then go to your NuGet package manager and install the updated version.

- 135
- 1
- 8
update xamarin.forms
update xamarin.forms from NuGet managers and clear all NuGet caches

- 1
- 1
Try using a lower version for the package you want to install I was getting the same error while installing jwtbearer in .net 7 Then I used '6.0.16' version of Microsoft.AspNetCore.Authenciation.JwtBearer

- 1
- 1
First, see your project Target Framework and install the same version of the NuGet package. I hope this is helpful

- 1
-
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? **If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient.** Can you kindly [edit] your answer to offer an explanation? – Jeremy Caney Jul 01 '23 at 17:53
You should do following processes:
- clear all entity frame work packages include: Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Tools, Microsoft.EntityFrameworkCore.SqlServer,Microsoft.EntityFrameworkCore.Design
- do scaffolding
- install again all above entity frame work packages

- 25
- 4