***This blog post is part of the series Visual Studio underutilized features***

Visual Studio Commands

Almost all interactions in visual studio in form of menus, dialog boxes, windows, toolbars etc. are executed using commands. Some of them are even available from command line argument. For instance, you can build your solution from “Developer Command Prompt for VS2012” that ships with visual studio tools, using command:
> devenv /Build HelloWorld.csproj
To get good understanding on built-in commands in visual studio IDE, open up the “Command Window” in visual studio from (View -> Other Window -> Command Window), you will notice a command prompt. All your menu items, toolbar items, editor context menu, nearly everything that can be done using user interface can be actually executed via commands and you can validate this in “Command Window”

For instance, try executing a command e.g. File.NewProject, the visual studio will open the file new dialog. The same command is executed when you select File -> New Project or press Ctrl+Shift+N.
The key point here is to understand that visual studio IDE uses centralize command system binded with user interface element. If you have idea about command pattern or you have worked with commands in Windows Presentation Foundation, you must be having good understanding of this concept.
Besides learning shortcuts, Command window is quick way to execute commands in Visual Studio instead of achieving the same by navigating though menus with mouse intervention. This saves a lot of time, part of the reason is because it’s difficult to memorize many shortcuts.
Visual Studio 2012 provides a great alternative in form of “Quick Launch” to quickly search/navigate to different commands, menus, dialogs, tool windows etc. However, I think that Quick search is a great alternative available in Visual Studio 2012

External Tools and Commands

Another nice option that visual studio provides is to create an external command that can be bind with an external tools.  You will find “External Tools” option under “Tools” menu.
You will observe that there is already some list of pre-defined external tools defined with associated commands along with the arguments etc.

Here we can create our custom menu item. For example, I want to view solution (.SLN) file in editor. Out of box solution context menu does not ship with item to open solution file in editor, however you can do this from windows explorer/directory. So let’s add a new external tool with title “Open Solution File in Notepad” and associate command of notepad.exe. The arguments will be $(SolutionDir)$(SolutionFileName) which together refers to complete path to solution file.
What it does that given any solution open, it will look run the notepad command with solution file path as argument. That’s it. Now you will see the newly added item in Tools menu.

So, if you haven’t, go ahead and try using command window.

Categories: Visual Studio


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *