Tuesday, March 8, 2011

ReSharper: remove unused references.

Today I was cleaning up unused references in a Visual Studio solution. Thanks to ReSharper it was not as tedious as I fought at first. Another great feature provided by this tool saved me a couple of minutes (or maybe hours):  http://www.jetbrains.com/resharper/features/navigation_search.html#Find_ReferencedDependent_Code.
To use it select the referenced assembly in the solution browser and choose "Find Code Dependent on Module" from the context menu. If the assembly isn't used anywhere in the current project ReSharper will show a message box saying: "Code dependent on module XXXXXXX was not found". In this case you can remove this reference safely.

6 comments:

Anonymous said...

Another way is to use the following vs extension:

http://visualstudiogallery.msdn.microsoft.com/36a6eb45-a7b1-47c3-9e85-09f0aef6e879

It's free and much faster than resharper

Anonymous said...

Take a look at Reference Assistant VS2010 extension by Lardite group. It is completely free but it still works very well!

http://visualstudiogallery.msdn.microsoft.com/fc504cc6-5808-4da8-ae86-8d3f9ed81606

Alex said...

Thank you for the hints guys! Will check these extensions out. Thanks!

Beau Gough said...

Both Resharper 6.1 and the Muse one which "Anonymous" mentioned remove references which are needed by the build. I haven't tried the Lardite one.
The Muse one is much slower for me.
I'm using VS2010.

Beau Gough said...

After further investigation, comparing the results of Resharper 6.1 and the Muse VS extension, I can see that Resharper is able to detect more unused references than Muse but both still make mistakes and can remove too many references causing the build to fail.

My conclusion is that if to use Resharper if you have it at your disposal (it's not cheap though).

Alex said...

Thank you for your comments Beau! It's true. Removing unused references is much easier since Resharper 6.1. With version 7.0 you can even remove unused references for the entire solution at once: http://www.jetbrains.com/resharper/whatsnew/#remove-unused-references. I agree that if you already have Resharper there is no need to install other extensions for removing "dead references" anymore. Resharper is not cheap but removing unused references is not the only feature it has :)