Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing all unused references from a project in Visual Studio projects

I just wondered if it possible within various Visual Studio versions to automatically remove all references from a project that were never been used?

In your answer, please specify which version of VS the solution applies to.

like image 800
KroaX Avatar asked Jul 01 '10 10:07

KroaX


People also ask

How do I delete project dependencies in Visual Studio?

To remove dependencies from projectsIn Solution Explorer, select a project. On the Project menu, choose Project Dependencies. The Project Dependencies dialog box opens. On the Dependencies tab, select a project from the Project drop-down menu.

How do I remove unused variables in Visual Studio 2019?

In the first preview build of Visual Studio 2019 version 16.10, Microsoft adds a Remove Unused References command. It can be invoked by right-clicking on the project name or the dependencies node in Solution Explorer and select the " Remove Unused References... " command from the menu.

Where are Visual Studio references stored?

References are stored in the . csproj file.


1 Answers

If you have Resharper (plugin) installed, you can access a feature that allows you to analyze used references via Solution Explorer > (right click) References > Optimize References...

http://www.jetbrains.com/resharper/webhelp/Refactorings__Remove_Unused_References.html

This feature does not correctly handle:

  • Dependency injected assemblies
  • Dynamically loaded assemblies (Assembly.LoadFile)
  • Native code assemblies loaded through interop
  • ActiveX controls (COM interop)
  • Other creative ways of loading assemblies

enter image description here

like image 148
Ernest Avatar answered Oct 14 '22 11:10

Ernest