
It's funny, but for a long time I thought that the ability to launch third-party applications from
Visual Studio is not worthy of attention. Serious integration requires the development of a plugin, and a point!
As it turned out, I was wrong. There are many scenarios where
External Tools allows you to quickly extend the capabilities of
Visual Studio .
Just yesterday, my good friend asked a question - how to make an analogue of the
Open Containing Folder command from the
PowerCommands for Visual Studio 2010 package, but to call
Far Manager , not
Windows Explorer ? In the original, this command is available in the context menu of
Solution Explorer , it opens
Windows Explorer and sets the cursor on the file for which it was called.
')
My first idea (there is nothing simpler - you need to download
PowerCommands.vsix from the
Visual Studio Gallery , unpack it, parse it with
Reflector , overlap with the
Visual Studio extension guidelines and quickly write an analog) did not find understanding - writing plugins for
Visual Studio (if this is not an extension of the editor) is still a very nontrivial task, and if there is no experience, then even with examples and step-by-step guides, its solution will take no less than half a day - if not the whole day!
After a little more thought, I decided that the
External Tools mechanism is quite suitable for this purpose! And, really, the creation of the “team”
Open Containing Folder in FAR took me no more than half an hour.
Let's see how this can be done.
Register External Tool
The first step is to register a new
External Tool .
To manage external tools in
Visual Studio there is an
External Tools window (
Main Menu >
Tools >
External Tools ...):
To add a new tool, you need to click the
Add button and specify some parameters:
Title : Open Containing Folder in FAR
Command : "C: \ Program Files \ Far2 \ Far.exe"
Arguments : $ (ItemPath)
The
Initial Directory parameter in this case can be left empty.
The list of arguments that can be used for the
Arguments and
Initial Directory parameters can be found in the MSDN Library in the
External Tools section of
Visual Studio / Arguments for External Tools . In addition, you can use the special menu that opens when you press the button

.
This is what I ended up with:
After closing the
External Tools window, the
Open Containing Directory in FAR item appears in the
Main Menu >
Tools menu. Selecting this item will launch
Far Manager , and the cursor will point to:
- File opened in the editor - if you have accessed the menu from the editor;
- File selected in Solution Explorer - if you accessed the menu from Solution Explorer .
Running CMD Scripts
The result of the
Open Containing Directory in FAR command is shown in the figure below. And this result, to put it mildly, is not impressive ... Which is not surprising, since
Far Manager I have configured to work with a different window size.
In order to open the window of the usual sizes, you need to write a small script:
mode con cols=132 lines=59 "C:\Program Files\Far2\Far.exe"
To run this script from
Visual Studio, you will need to save it to disk (I saved it as
C: \ psg \ Tools \ VSOpenInFAR \ VSOpenInFAR.cmd ) and change the Command parameter so that it points to this script:
Now the results can be considered quite satisfactory, the
Far Manager window has dimensions that I am used to.
Note
Visual Studio uses
cmd.exe to run CMD scripts, calling it in the following form:
cmd.exe /c ""C:\psg\Tools\VSOpenInFAR\VSOpenInFAR.cmd" "C:\psg\...\Class2.cs""
If the
Close on exit option is not checked, the call form changes slightly:
cmd.exe /c ""C:\psg\Tools\VSOpenInFAR\VSOpenInFAR.cmd" "C:\psg\...\Class2.cs" & pause"
This should be kept in mind to avoid problems with quotes and script completion codes!
Calling the External Tool from the context menu
Ok, we’ve got a workable tool, now you can do adding goodies - for example, add the
Open Containing Folder in FAR call to the
Solution Explorer context menu.
This requires:
- Open the Customize window ( Main Menu > Tools > Customize ... ).
- Go to the Commands tab.
- In the Choose a menu or toolbar to rearrange section, select the Context menu item, and then select the Project and Solution Context Menus | Item .
The next step is to select the appropriate position for the new menu item. I decided to post it next to the
Open Containing Folder item.
Now you need to insert into the selected position a new menu item, for this purpose is the
Add Command button, which calls the window of the same name.
In this window, you need to select the
Tools category, and then specify the
External Command 6 command - unfortunately, the commands for running
External Tools can be identified only by their sequence number. After clicking OK, a new item will appear in the context menu -
External Command 6 .
The final step is to rename the menu item. To do this, click on the
Modify Selection button and in the
Name field specify the name of the tool -
Open Containing Folder in FAR .
The result of these manipulations is shown below - the
Open Containing Folder in FAR item is available in the context menu of the
Solution Explorer :
Additional Information
Additional information on working with
External Tools can be obtained on MSDN:
- External Tools in Visual Studio
- Arguments for External Tools