Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove unused references

I want to know if any tool exists for removing unused references (not unused using directives) within a .NET C# project.

like image 777
Cornel Avatar asked Nov 24 '09 08:11

Cornel


People also ask

How do I remove a reference from a website?

In Solution Explorer, Right-click on the project. In this view, go to References, and remove the offending reference.

How do I remove unused using Visual Studio 2019?

CTRL + K + E Will sort and remove your unused usings.

How do I delete all unused imports in Visual Studio?

First is putting your cursor on one of the grayed out lines and clicking the light bulb, then clicking Remove Unnecessary Usings. (NOTE: The shortcut key for this is CTRL-.) When the action is executed the references will be cleaned up.

How do I remove unused NuGet packages?

Clean up project references and NuGet packages in Visual Studio. Firstly, Right Click on the Project, and select “Remove Unused References”. This will bring up the “Remove Unused References” Dialog that shows the projects and all unused packages. Here, you can again choose if you want to remove them or keep it as it is ...


2 Answers

I am unaware of such a tool off the top of my head - I do know that Visual Studio does not include one by default. However, referenced assemblies that are not actually used by code in the project are automatically removed by the C# compiler from the list of assemblies referenced by the compiled program. If you use Reflector, you can compare the list of actual references to the list of references in the project, and remove the unnecessary ones that the project includes based on that.

like image 82
Sam Harwell Avatar answered Oct 15 '22 08:10

Sam Harwell


Resharper will certainly do the trick...

like image 27
Cédric Rup Avatar answered Oct 15 '22 08:10

Cédric Rup