RSS

Tag Archives: Remove References

Remove unused references in a .NET project

Everybody might have run into troubles of having dozens of references in his Visual Studio project.
But how can you remove them. You can select each reference, remove it and hope that the solution will compile again. To be honest, this is a very long process. But how can you speed up this process?

Context Menu of ReSharper
If you use the add-in Jetbrain’s ReSharper then you have a very powerful context menu point. It is called “Find Symbols External to Scope“. This function can be found by right clicking on any of the solution projects and selecting the corresponding menu item.

After some time of calculation you will get following picture:

Referenced Code

Here you can perfect see which of the referenced references are no longer of use. For example System.Xml.Linq can be omitted and removed from the references.

Note: It might be that after removing several references the solution will not compile anymore, because there are some cross-references needed. If this is the case reference these libraries manually or by using the context help of ReSharper by pressing ALT+RETURN (default configuration).

Context Action

Update

Starting with ReSharper 6.1 this process will be much easier. In that version you can easily search for references that can be removed. This is done by doing a right click on a Project Folder, Selecting “Refactor” and then “Remove Unused References”. Than you will see following dialog where you can select the references that you want to remove.

Remove Unused References
If you click “Analyze Used References” you will get the screen like shown before. In the new version the window is a little bit updated, but the core function stays the same.

But beware: Clicking Next will remove all references listed without confirmation dialog.

Advertisements
 
Leave a comment

Posted by on January 18, 2011 in Visual Studio

 

Tags: