суббота, 24 декабря 2011 г.

Optimizing assembly references with ReSharper 6.1

Hi!

Today I'm going to talk about new features of ReSharper 6.1th version, which allow you to easily manage your existing assembly references, see referenced assemblies usages, and remove unused references.

Three new features are coming along with a new 6.1 version of ReSharper:

1. Optimize References


Optimize References is a main feature for analyzing your referenced assemblies. This feature can be called on a single project and displays this module's unused and used assembly references. It does not require your project to be compiled, so you can call it even if your project is currently broken.




One of the coolest things about this feature is that it allows you to see usages of a concrete referenced assembly, namespace or type, filter them by their kind, group them and navigate from them directly to your source code. On the screenshot below is illustrated why exactly my project references System.Drawing.dll and what types of that assembly are used and where.




Different icons mean different usage kinds like read, write, attribute, invocation and other kinds of usages familiar to you from ReSharper's navigation features. However, one kind of usages is unique for Optimize References. This kind of usage is called 'compiler related usage' and indicates implicit (non-direct) assembly reference usages required for compiler.
The simplest case is the case when related usages are caused by a type's hierarchy. That is, if you use a type, then you have to reference all assemblies containing this type's supertypes. Unfortunately, this is just one example of many other much more complicated ones... :)

Besides just observing, you can delete unused assembly references directly from this tool window. You just need two buttons to remove all unused references or just selected.




Note that this feature will also delete all redundant C#, VB.NET or XAML namespace import directives, which reference namespaces from the removed referenced assemblies.

2. Remove Unused References refactoring

This refactoring quickly detects unused assembly references without displaying their usages. It works faster than Optimize References. It is very useful if you do not want to analyze usages but just want to quickly clean up your project references.


'Analye Used References...' button will open Optimize References tool window.

3. Safe delete on assembly references refactoring
That is, now you can press Alt+Del on the selected assembly references from Solution Explorer. They will be either silently removed, or you will get a window indicating that some of the selected references are used.





These three features introduced in ReSharper 6.1 will definitely help you to manage your references. By the way, if you want to observe code referenced in the scope, other than project (for example, folder or method's body), you can use ReSharper's 'Find Symbols External To Scope' and 'Find Dependent Code' features.

1 комментарий: