How can you find the unused NuGet packages in a solution?
I\'ve got a number of solutions where there are a lot of installed packages, and a large number of them are
I don't think there is a default way to find this out. The primary reason being the variety of things these packages can do from referencing an assembly to injecting source code to your project. You may want to check the Nuget.Extensions though. The following thread on codeplex talks about an audit report of nuget packages.
http://nuget.codeplex.com/discussions/429694
(NuGet has been moved from Codeplex to GitHub. Archive of the above link:) https://web.archive.org/web/20171212202557/http://nuget.codeplex.com:80/discussions/429694
ReSharper 2016.1 has a feature to remove unused NuGet.
It can be run on a solution and on each project in a solution and it does the following things:
Unfortunately, this doesn't work for project.json
projects (RSRP-454515) and ASP.NET core projects (RSRP-459076)
You can use the Visual Studio Extension ResolveUR - Resolve Unused References.
Resolve unused references including nuget references in Visual Studio 2012/2013/2015 projects via menu item at solution and project nodes Solution Explorer Tool Window
It's not an easy task, so I suggest to make a backup and/or commit before, just in order to rollback if something went wrong.
This is manual labor, but it works.
Use ReSharper or similar code analysis tool to identify any unused references in your projects and uninstall the nuget in the corresponding projects.
Sometimes uninstalled nugets still linger in the Installed packages and Updates lists in the Manage NuGet Packages dialog. Close Visual Studio then delete the packages
folder, then reopen the solution and restore your nugets.
You can accomplish this using ReSharper 2019.1.1.
Right click on the project > Refactor > Remove Unused References.
If your project is small, you can also use: project > Optimize Used References . . .
A window will pop up. Select all references and remove them all. Then go back and re-add the ones that give you a compiler error.