Wednesday, January 19, 2011

Visual studio resolve usings.

I had the absolute joy of hanging out at the Tampa .NET Developer Group Meeting last night. Here is a tip I mentioned briefly at the meeting around resolving and optmizing namespaces.

I know a lot of us are hardcore ReSharper users and can do all kinds of jedi-like moves in the Visual Studio 2008 IDE. However, get us without ReSharper at times and we just stare at the keyboard in bewilderment wondering why namespaces aren't resolving, usings are being optimized, and refactorings are not taking place at blinding speeds, etc.

It turns out, Visual Studio 2008 actually has good support for resolving namespaces and optmizing using statements that can get you the functionality if you are not using ReSharper.



Resolving Namespaces

When you are writing code and Visual Studio places a small red notification rectangle at the end of the class,







Pressing Ctrl + . will bring up a context-sensitive menu that allows you to add a using statement or optionally fully qualify the path to the class.







Clicking the Enter Key will automatically add using System.Collections.Generic; with the other using statements, requiring no touch of the mouse.

This also works with attributes as well. Adding an attribute that needs a using statement to qualify its namespace will cause the same red notification rectangle to appear:







and pressing Ctrl + . will allow you to add the using statement, etc.







Optimizing, Removing, and Sorting Unused Using Statements

The other nice thing that ReSharper does is remove unused using statements using Ctrl+Alt+O.

We can get that using Visual Studio 2008, because you may have noticed the cool context-sensitive Organize Usings Option:







Very, very cool, but this needs to have a shortcut because we will be using it often. I want to use the familar Ctrl+Alt+O shortcut that I get from ReSharper ( you can choose your own ) so I need to map the shortcut to the Edit.RemoveAndSort Command in the keyboard options:







Now when I type Ctrl+Alt+O in the code editor it will remove all unused using statements in the current file as well as sort those using statements that are being used.

Very cool! Hope this helps.

8 comments:

Harry said...

Get your Free Credit Score Report - free for 30 Days. Unique anti-ID theft security measures included in this fantastic package as part of the service. Free Credit Score Report

Kevin said...

Thanks for taking this opportunity to discuss this, I feel fervently about this and I like learning about this subject.childrens furniture

Harry said...

I am amazed to see such an amazing post. Keep up the good work.school furniture

Harry said...

Thanks for taking this opportunity to discuss this, I feel fervently about this and I like learning about this subject.Televisore lcd

Harry said...

Thank you for such a wonderful post. I enjoyed every bit of it.televisori lcd

Harry said...

Thanks for taking this opportunity to discuss this, I feel fervently about this and I like learning about this subject.refrigerator repair

papayoung said...

cheap ted baker dresses that you would Ted Baker Outlet uk be here, ah, I give you the phone several times how you do not pick ah. At the moment cheap distracted lips to kiss cheap, and hold the phone cheap ted baker dresses look unhappy cheap ted baker dresses to go over, and then very naturally into his trouser cheap, took out a cheap ted baker dresses promise poultry's latest phone. cheap staggering, ted baker uk sale eyeball violent conflic.

fanny said...

When the sadness is surging in the chest, the warm will come in time, and ease the pain in your heart. This is life.
_________________________
If you like playing games,you would like it:
RS Gold and rsgoldfast.com