views:

2524

answers:

5

What is the keyboard shortcut to expand the little red line that gives you the menu where you can choose to have the necessary Using statement added to the top of the file?

My Googling skills have not proved fruitful.

+8  A: 

Alt+Shift+F10 will show the menu associated with the smart tag.

Jeff Yates
+19  A: 

As will CTRL+. which I find easier to type.

Orion Adrian
Yup, I guess it's what you're used to. I have no difficulty with Alt+Shift+F10 whereas Ctrl+. feels totally alien. I guess we'll accept anything given enough conditioning. :D
Jeff Yates
I have one of the Microsoft keyboards with their Function lock... man I hate that thing.
Orion Adrian
I have one of those at home. Function lock was a dumb idea.
Jeff Yates
Wow, didn't know about Ctrl+. or Alt+Shift+F10, but always wondered if there was such a short-cut.I also have a function lock keyboard, but it always remembers its state, so no problem here (Microsoft Natural Ergonomics Keyboard 4000).
OregonGhost
+1  A: 
  • Context Menu key (one one with the menu on it, next to the right Windows key)
  • Then choose "Resolve" from the menu. That can be done by pressing "s".
James Curran
+2  A: 

Just stumbled upon this question years after it was added. I can highly reccommend checking out the visual studio pluin Resharper. It has a QuickFix feature that does the same (and a lot more).

But the Resharper doesn't require the cursor to be located on the actual code that requires a new namespace. Say, you copy/paste some code into the source file, and just a few clicks of "Alt+Enter", and all the required usings are included.

Oh, and it also makes sure that the required assembly reference is added to your project. Say for example, you create a new project containing NUnit unit tests. The first class you write, you add the [TestFixture] attribute. If you already have one project in your solution that references the nunit dll, then Resharper is able to see that the TestFixtureAttribute comes from that dll, so it will automatically add that assembly reference to your new project.

And it also adds required namespaces for extension methods. At least the Resharper version 5 beta does. I'm pretty sure that Visual Studio's build in resolve function doesn't do that.

On the down side, it's a commercial product, so you have to pay for it. But if you work with software commercially, the gained productivity (the plug in does a lot of other cool stuf) outweighs the price tag.

Yes, I'm a fan ;)

Pete
A: 

Quite an old thread but here are my comments:

In Visual Studio 2010 you will find the keyboard command to resolve namespaces in a command called View.ShowSmartTag. Mine was also mapped to Shift-Alt F10 which is a lot of hassle - so I usually remap that promptly.

On Pete commenting on Resharper - yes, for anyone with the budget, Resharper makes life an absolute pleasure. The fact that it is intelligent enough to resolve dependencies outside the current references, and add them both as usings and references will not only save you countless hours, but also make you forget where all framework classes reside ;-) That is how easy it makes development life... Then we have not even started on ReSharper refactorings yet.

DevExpress' CodeRush offers no assistence on this regard; or nothing that is obvious to me - and DevExpress under non-expert mode is quite forthcoming in what it wants to do for you :-)

Last comment - this IDE feature of resolving dependencies is so mature and refined in the Java IDE world that the bulk of the internet samples don't even show the imports (using) anymore.
This said, Microsoft now finally has something to offer on this regard but it is also clear to me that Microsoft development (for many of us) has now come full circle - the focus went from source, to visual designers right back to focus being on source again - meaning that the time you spend in a source code view / whether it is C#, VB or XAML is on the up and the amount of dragging and dropping onto 'forms' is on the down. With this basic assumption, it is simple to say that Microsoft should start concentrating on making the editor smarter, keyboard shortcuts easier, and code/error checking and evaluation better - the days of a dumb editor leaving you to google a class to find out in which library it resides are gone (or should be in any case) for most of us.

Gawie Kellerman