7

I have been doing some Android development and found that Ctrl+Shift+O shortcut is quite handy for someone like me who is still getting used to what imports are necessary for different objects on the screen. I have also been doing vb.net development in Visual Studio 2008 and by mistake tried that shortcut however it tried opening a form or something similar. So my question is: is there a shortcut that lets us import all missing references or remove the unnecessary ones in Visual Studio 2008?

User 12345678
  • 7,714
  • 2
  • 28
  • 46

2 Answers2

3

To Remove Unnecessary Import Directives

I can confirm that in Visual Studio 2012 and Visual Studio 2010 there is a context menu option for the code-editor to remove, sort or remove and sort using directives in either Visual Basic.NET or C#. I've actually never used Visual Studio 2008 but a quick search reveals that it is possible in 2008 too (source).

..

In order to hook this functionality up to a hotkey all you need to do is:

  1. Go to Tools > Options
  2. Expand the root node annotated 'Enviroment' and then click the node annotated 'Keyboard'
  3. Search for Edit.RemoveAndSort and assign your hotkey of choice.

To Add Unknown Import Directives

I use this plugin called ReSharper which presents me with an interface like this when I reference a class that does not have an appropriate import directive:

enter image description here

If you don't want to use ReSharper (it's pretty expensive) then Visual Studio has a slightly less productive but just as effective interface. You should see the class reference underlined in red and if you hover your mouse to the red line you should see a little dialog displaying the option to add a reference to the namespace. You can also press CTRL + . to show the dialog quickly.

User 12345678
  • 7,714
  • 2
  • 28
  • 46
1

From this link:

Automatic namespaces import

Looks like Shift + ALT + F10 will do the trick.

Community
  • 1
  • 1
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • That's View.ShortSmartTag, which is quite dope, to be fair, but doesn't fix all your usings in one fell swoop, which Ctrl+Shift+O does for Java's imports in Eclipse. – Mathieu K. Feb 26 '17 at 04:21