I’m way behind in my extension series. Relocation + New Job + Work Travel, it’s been a crazy year!

The Power Commands for Visual Studio are back! The Power Commands were an extremely popular add-in for Visual Studio 2008, giving you even more options for your IDE.

To Install

The Power Commands extension can be found on the Visual Studio Gallery at http://visualstudiogallery.msdn.microsoft.com/en-us/e5f41ad9-4edc-4912-bca3-91147db95b99

Please see this post on how to install extensions if you need additional help.

To Use

The Power Command options can be found all throughout the IDE. To help you discover what all the Power Commands do, I’m going to review each option below.

Pay close attention to the Choose Which Commands You Want To Use section. All commands are enabled by default, but if there are a few you never will use, or don’t want to use, you can disable them in Tools Options.

Format Document On Save

Ctrl+K, Ctrl+D is the keyboard shortcut to format the current document (found under Edit – Advanced – Format Document). This is very useful to know when you cut and paste code from a website or somewhere else that causes the formatting to go crazy.

But maybe you don’t want to think about keyboard shortcuts. Or maybe you just one less thing to worry about as you save the document.

You must enable the “Format Document On Save” option at the Tools – Options – PowerCommands – General page.

Now whenever you save a document, and formatting that’s off, as shown below

extra whitespace on line

will be corrected automatically.

corrected whitespace

Remove And Sort Usings On Save

Alas, this is only for C#. On the C# context menu, there are the “Organize Usings” commands.

Remove and Sort Usings on context menu

These options are great when you want to clean up your using statements at the top of the file, by removing any using statements not actually being used and also by sorting them in alphabetical order.

non-sorted using statements

Talk about a huge timesaver!

But let’s save even more time by having the editor do this automatically whenever you press save. You can find the option to enable this feature at Tools – Options – PowerCommands – General page.

Remove and Sort Usings

Let’s take this awesome one step further. Instead of removing unused using statements at the file level, let’s remove and sort them at the project level!

Remove and Sort Usings on context menu

As illustrated above, the command “Remove and Sort Usings” can be found on the Solution Explorer context menu at both the Solution level and at the individual project levels.

Clear All Panes

In the Output Window, you can have multiple panes, the most common being Build and Debug. There’s a “Clear All” button (indicated below) that will just clear the current output window pane.

If you want to clear all output sub-windows at once, press the “Clear All Panes” button located just to the right of the “Show Output From” drop down.

Clear All Panes on Output Window

Copy Path

No more having to open a file to copy its file path from the file tab.

This command copies the full path of the currently-selected item to the clipboard. It works with the solution node, a project node, any project item node, and any folder.

Copy Path on Solution Explorer context menu

Email Code Snippet

Exactly as it sounds.

Select some code in the editor, then right-click and select “Email CodeSnippet.”

Email CodeSnippet on context menu

And it also fills out the subject for you.

To: You
From: Me
Subject: CodeSnippet from Program.cs

Insert Guid Attribute

To add a GUID attribute to a class, right-click anywhere within the class and select “Insert Guid Attribute”, and those few extra keystrokes are done for you.

System.Runtime.InteropServices.GuidAttribute(...)

Show All Files

The only thing better than one “Show All Files” button is two “Show All Files” buttons! The one on the left is for the current project, but the one on the right is for the entire solution.

current project versus entire solution icons

Undo Close

ROCK ON!

How many of you like me close something only to realize in that instant that you wanted to look at something again. This command is for us!

To reopen the most-recently closed document, go to Edit – Undo Close. Keyboard shortcut is Ctrl+Shift+Z. It’ll even return the cursor to its last known position.

But it gets better…

Want to see all of your most-recently closed documents? Go to View – Other Windows – Undo Close Window.

Undo Close tool window

Collapse Projects

If you want to collapse everything under a project node, including any sub-nodes (this being the key difference from the standard Windows behavior), right-click and select “Collapse Project” from the Solution Explorer context menu.

Thus a project like this

fully expanded node in Solution Explorer

will collapse everything, including the Properties and the Resources.resx nodes, as shown below. (I expanded the XAMLVisualizer node for illustration purposes).

collapsed sub-nodes in Solution Explorer

This command works for solutions, projects, and solution folders.

Copy Class / Paste Class

On the Solution Explorer, select a project item (usually a class file) you want to copy. Right-click and select “copy class.” Now navigate to the project node and right-click to see the “Paste Class” command.

a copied class in solution explorer

It will also rename the class to avoid compiler errors.

Copy References / Past References

This command allows you to copy all your references for a project, then paste them into another project. No Add Reference Dialog needed!

Copy References on Solution Explorer

You can also do this across multiple instances of the IDE.

For C# projects, the command is found on the references node. For VB and ASP.NET projects, it is found on the project node.

Copy As Project Reference

Just like in the previous command, why use the Add Reference Dialog if you don’t have to. The “Copy As Project Reference” command found on the Solution Explorer context menu will allow you to copy a project (from its project node) and then paste it into another project node as a project reference.

Copy as Project Reference example

Edit Project File

One of my more popular tips, especially for those who work on MSBuild project files, is the ability to quick edit your project files without having to shut down Visual Studio and open up notepad. The tip was to Unload Project and Edit Project (all via Solution Explorer context menu).

The “Edit Project File” combines these two commands for you, unloading the project and opening the file in the editor for you.

Edit Project File in editor context menu

You’ll still need to Reload the project file when you’re done. The command is found by right-clicking on the project node.

Open Containing Folder

Similar to the command found on the File Tabs and in the Solution Explorer for a node, this command opens the containing folder for an item in the Solution Explorer.

Open Containing Folder on Solution Explorer context menu

Open Command Prompt

For The Win!

Open a Visual Studio command prompt directly from the Solution Explorer! I say a “Visual Studio” command prompt, and not just a command prompt, because this one has the Environment Variable set to know where devenv.exe lives. So no more having to be frustrated with “devenv is not recognized as an internal or external command….”

Open Command Prompt via Solution Explorer

Unload Projects / Reload Projects

Similar to the built-in command for unloading a project, the Unload Projects command (found on the Solution Explorer context menu for a project node) will unload all the projects in a solution. Useful for editing multiple MSBuild files.

Unload multiple projects example

And to reload all your projects, there’s the Reload Projects command.

Extract Constant

Found under the Refactor menu, the Extract Constant will do exactly what it sounds like it does. It will create a constant based on the selected text. For example, consider the Console.WriteLine() parameter I have below:

Extract Constant on context menu

Selecting this text, I can specify “Extract Constant”. It will bring up a dialog to allow me to specify scope and give the new string a name.

Extract Constant dialog box

Pressing enter creates the string, the WhoDat constant in this example.

image

Clear Recent File List

No longer having to go to the registry to clean up your recent files list. The “Clear Recent File List” command will do that for you. Go to File – Recent Files – Clear Recent File list.

Clear Recent File List on File - Recent Files menu

This will bring up the Clear Recent File List dialog for you to pick and choose what to delete.

Clear List dialog box

Wow! I have a lot of recent files!

Clear Recent Project List

Similar to the above tip, the Clear Recent Project list will allow you to clean up your recent project list. It is found at File – Recent Projects and Solutions – Clear Recent Project List.

Clear Recent Project List dialog box

Close All

Found on the File Tab context menu, this command will close all open documents.

Close All on File Tab Context menu

Choose which commands you want to use!

By default, all the power commands are enabled. To only enable those you’re going to use, you can go to Tools – Options – PowerCommands.

Tools - Options - Power Commands - Commands

And on the Commands page, you’ll find the full list of all the commands available with this extension.

All possible PowerCommands options to enable/disable