How do I delete NuGet packages that are not referenced by any project in my solution?

NugetVisual Studio-2012

Nuget Problem Overview


Somehow during the upgrade to VS2012 and .NET 4.5, I've managed to get NuGet confused. There are packages that appear in the package manager (and the packages folder) that I cannot delete (I believe they are legacy ASP.NET NuGet packages that have been replaced with new package names with the new version. They each have only a Manage button -- but no uninstall button. And when you look to see where they are used, you can see that they are referenced by none of the solution's projects? They are NOT displaying an Uninstall?

Nuget Solutions


Solution 1 - Nuget

I've found a workaround for this.

  1. Enable package restore and automatic checking (Options / Package Manager / General)
  2. Delete entire contents of the packages folder (to Recycle Bin if you're nervous!)
  3. Manage Nuget Packages For Solution
  4. Click the restore button.

NuGet will restore only the packages used in your solution. You end up with a nice, streamlined set of packages.

Solution 2 - Nuget

You can use Package Manager Console with command: Uninstall-Package PackageId to remove it, or just delete package folder from 'packages' folder under solution folder. More information about Package Manager Console you can find here: http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference

Solution 3 - Nuget

First open the Package Manager Console. Then select your project from the dropdown list. And run the following commands for uninstalling nuget packages.

Get-Package

for getting all the package you have installed.

and then

Uninstall-Package PagedList.Mvc

--- to uninstall a package named PagedList.MVC

Message

PM> Uninstall-Package PagedList.Mvc
Successfully removed 'PagedList.Mvc 4.5.0.0' from MCEMRBPP.PIR.

Solution 4 - Nuget

If you want to delete/uninstall Nuget package which is applied to multiple projects in your solutions then go to:

  1. Tools-> Nuget Package Manager -> Manage Nuget Packages for Solution

  2. In the left column where is 'Installed packages' select 'All', so you'll see a list of installed packages and Manage button across them.

  3. Select Manage button and you'll get a pop out, deselect the checkbox across project name and Ok it

The rest of the work Package Manager will do it for you.

Solution 5 - Nuget

VS2019 > Tools > Options > Nuget Package Manager > General > Click on "Clear All Nuger Cache(s)"

Solution 6 - Nuget

If you have removed package using Uninstall-Package utility and deleted the desired package from package directory under solution (and you are still getting error), just open up the *.csproj file in code editor and remove the tag manually. Like for instance, I wanted to get rid of Nuget package Xamarin.Forms.Alias and I removed these lines from *.csproj file.

Removing nuget package from msbuild script

And finally, don't forget to reload your project once prompted in Visual Studio (after changing project file). I tried it on Visual Studio 2015, but it should work on Visual Studio 2010 and onward too.

Hope this helps.

Solution 7 - Nuget

An alternative, is install the unused package you want to delete in any project of your solution, after that, uninstall it and Nuget will remove it too.

A proper uninstaller is needed here.

Solution 8 - Nuget

Solution 1

Use the powershell pipeline to get packages and remove in single statement like this

Get-Package | Uninstall-Package

Solution 2

if you want to uninstall selected packages follow these steps

  1. Use GetPackages to get the list of packages
  2. Download Nimble text software
  3. Copy the output of GetPackages in NimbleText(For each row in the list window)
  4. Set Column Seperator to ( if required
  5. Type Uninstall-Package $0 (Substitute using pattern window)
  6. Copy the results and paste them in Package Manage Console

That be all folks.

Solution 9 - Nuget

One NuGet package can reference another NuGet package. So, please be very careful about inter-package dependencies. I just uninstalled a Google map package and it subsequently uninstalled underlying packages like Newtonsoft, Entity Framework, etc.

So, manually deleting particular package from packages folder would be safer.

Solution 10 - Nuget

From the Package Manager console window, often whatever command you used to install a package can be used to uninstall that package. Simply replace the INSTALL command with UNINSTALL.

For example, to install PowerTCPTelnet, the command is:

Install-Package PowerTCPTelnet -Version 4.4.9

To uninstall same, the command is:

Uninstall-Package PowerTCPTelnet -Version 4.4.9

Solution 11 - Nuget

If you want to use Visual Studio option, please see How to remove Nuget Packages from Existing Visual Studio solution:

> Step 1: > > In Visual Studio, Go to Tools/NuGet Package Manager/Manage NuGet Packages for Solution…

> Step 2: > > UnCheck your project(s) from Current solution

> Step 3: > > Unselect project(s) and press OK

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHoward PinsleyView Question on Stackoverflow
Solution 1 - NugetJames LView Answer on Stackoverflow
Solution 2 - NugetPavel BakshyView Answer on Stackoverflow
Solution 3 - NugetAbdus Salam AzadView Answer on Stackoverflow
Solution 4 - Nugetuser1786058View Answer on Stackoverflow
Solution 5 - NugetZach IoannouView Answer on Stackoverflow
Solution 6 - NugetA.B.View Answer on Stackoverflow
Solution 7 - NugetD.RosadoView Answer on Stackoverflow
Solution 8 - NugetirfandarView Answer on Stackoverflow
Solution 9 - NugetAkiView Answer on Stackoverflow
Solution 10 - NugetJazimovView Answer on Stackoverflow
Solution 11 - Nugetuser1214835View Answer on Stackoverflow