Visual-studio – Removing all unused references from a project in Visual Studio projects

visual studio

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.

Best Answer

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