ReSharper | Find | Optimize References
The Optimize References feature helps manage your existing project references, browse usages of referenced assemblies, and remove unused references. You can invoke this feature on any single project and use the Analyze References window to analyze and optimize project references.
This feature does not require your project to be compiled, which means you can invoke it even if your project is currently broken.
Analyzing project references
The Analyze References tool window displays assembly references that are both unused and used in the current project, and shows how exactly references are used. To explore usages of a specific assembly, namespace or type, you can filter them by kind and group them.
The symbol icons could help you to distinguish between types of items. Each usage is displayed with the line number and column; different icons mean different kinds of usages like read, write, attribute, or invocation usage. You can double-click it to navigate directly to the source code.
- In the Solution Explorer, select a project that you want to analyze or its References node.
Do one of the following:
- Choose ReSharper | Find | Optimize References.
- Right-click the selection and choose Optimize References in the context menu.
- Press Ctrl+Alt+YCtrl+Alt+Y.
Use controls in the
window to explore project references.
Removing unused references
The easiest way to clean up project references is to click Remove All Unused References . If you want ro retain some unused references or remove some of the used references (and manually resolve the compilation errors that follow), you can make the corresponding selection and click Remove Selected References .
When you remove project references using these buttons, ReSharper also deletes all redundant C#, VB.NET, XAML, or Razor namespace import directives, which reference namespaces from the removed assemblies.
All Visual Studio projects must reference mscorlib and, starting from Visual Studio 2010, System.Core assemblies. These assemblies are marked with the pin icon and you cannot remove these references.
References that are needed for compilation, independently of whether they are used or not, are displayed in the References required by the compiler group. References in this group are normally have 'related usages', that is, implicit (non-direct) usages. In the simplest case, related usages are caused by a type???s hierarchy. That is, if you use a certain type, you have to reference all assemblies containing that type???s supertypes.
If you only need to remove unused references without analyzing all project references, simply choose Remove Unused References on the project's context menu and follow the steps of the Remove Unused References refactoring.
There is yet another way of cleaning project references. You can expand the References node in the Solution Explorer, select the references you want to remove and select ReSharper | Refactor | Safe Delete or press Alt+DeleteCtrl+R,D or Alt+Delete to invode the Safe Delete refactoring, which either silently removes unused references or opens a confirmation dialog indicating that some of the selected references are used (and shows how they are used).