Skip to content

Removing unused Nuget Packages

After working with Visual Studio and R# for many years now I discovered this feature just yesterday. Maybe some of you find it useful too.

I removed code that was depending on an external Nuget Package. Because the code is gone my project didn’t need the Nuget Package anymore. How to fast and safely remove the references and the package?

Let’s check the currently installed packages first:

resharper_remove_unused_references_1

Instead of opening the Nuget Packagemanager and uninstalling things manually there is faster way: right click on the project in the Solution Explorer and go into R# Refactor menu. There you’ll find the Remove unused references menu item.

resharper_remove_unused_references

This command will show you a dialog where one not only can select the plain assembly references to remove but also the references that come from a installed Nuget Package. This dialog shows a different icon for package references. See the highlighted item.

resharper_remove_unused_references_2

Clicking next will remove the selected references. For references that where introduced by an installed package the package is uninstalled too. Means your package folder is cleaned and the package is also removed from the package.config / .csproj.

The following show that not only the reference but also the package was removed:

resharper_remove_unused_references_3

Its a nice timesaver!

3 thoughts on “Removing unused Nuget Packages Leave a comment

  1. Can’t find “Refactor” menu item… Which Visual Studio does your article apply for? Tsk. Define your terms mate!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s