Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove unused references (!= usings) in C# project without Resharper?

Is there any way of removing unused references to assemblies, in a C# project, without the help of Resharper? The MSDN documentation does outline something for Visual Basic, but I couldn't find the same dialogs for C#.

like image 626
Rohit Avatar asked Sep 22 '09 08:09

Rohit


People also ask

How do I delete all unnecessary Usings in Visual Studio?

Go to Tools > Options > Text Editor > C# > Code Style > Formatting. It has an experimental Format Document Settings where you can have Visual Studio clean up your code. Two of the options are to "Remove unnecessary usings" and "Sort usings". Check these two and you're good to go!

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

How do I remove a reference from Rider?

Remove unused referencesPress Ctrl+Shift+R and then choose Remove Unused References.

How do I delete unused namespaces in Visual Studio 2022?

Navigate to Tools > Options > Text Editor > Code Cleanup. Add a check in the "Run Code Cleanup profile on Save." Be sure to select the appropriate profile you want to execute automatically whenever you save!


1 Answers

There is no build in support in Visual Studio to find unused assembly references in a C# project.

A workaround is, to remove a possible unused assembly, compile the project and look if it compiles successfully. If it´s the case an unused assembly was removed. Otherwise the removed assembly was necessary and it should be added again.

To check what assemblies are used by other assemblies you can use NDepend.

like image 156
Jehof Avatar answered Oct 13 '22 16:10

Jehof