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.
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.
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.
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
will be corrected automatically.
Alas, this is only for C#. On the C# context menu, there are the “Organize Usings” commands.
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.
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.
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!
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.
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.
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.
Exactly as it sounds.
Select some code in the editor, then right-click and select “Email CodeSnippet.”
And it also fills out the subject for you.
To: You From: Me Subject: CodeSnippet from Program.cs
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.
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.
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.
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
will collapse everything, including the Properties and the Resources.resx nodes, as shown below. (I expanded the XAMLVisualizer node for illustration purposes).
This command works for solutions, projects, and solution folders.
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.
It will also rename the class to avoid compiler errors.
This command allows you to copy all your references for a project, then paste them into another project. No Add Reference Dialog needed!
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.
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.
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.
You’ll still need to Reload the project file when you’re done. The command is found by right-clicking on the project node.
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.
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….”
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.
And to reload all your projects, there’s the Reload Projects command.
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:
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.
Pressing enter creates the string, the WhoDat constant in this example.
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.
This will bring up the Clear Recent File List dialog for you to pick and choose what to delete.
Wow! I have a lot of recent files!
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.
Found on the File Tab context menu, this command will close all open documents.
By default, all the power commands are enabled. To only enable those you’re going to use, you can go to Tools – Options – PowerCommands.
And on the Commands page, you’ll find the full list of all the commands available with this extension.