Visual Studio also has External Tools ...

    It's funny, but for a long time I thought that the ability to run third-party applications from Visual Studio is not worthy of attention. Serious integration requires plugin development, and that’s it!

    As it turned out, I was wrong. There are many scenarios when External Tools will quickly expand the capabilities of Visual Studio .

    Just yesterday, a good friend of mine asked a question - how to make an analogue of the Open Containing Folder command from PowerCommands for Visual Studio 2010 , but to invoke Far Manager , and not Windows Explorer ? In the original, this command is available in the context menu of Solution Explorer , it opensWindows Explorer and sets the cursor on the file for which it was called.

    My first idea (there is nothing easier - you need to download PowerCommands.vsix from the Visual Studio Gallery , unzip it, parse it with a Reflector , cover it with Visual Studio extension guides and quickly write an analogue) I didn’t understand - writing plugins for Visual Studio (if this is not an extension of the editor) is still a very non-trivial task, and if there is no experience, then even with examples and step-by-step manuals, its solution will take no less than half a day - if not a whole day!

    After thinking a little more, I decided that for these purposes the mechanism is quite suitableExternal Tools ! And, indeed, the creation of the “team” of 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 .

    For managing 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) In this case, the Initial Directory

    parameter 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 under External Tools in Visual Studio / Arguments for External Tools . In addition, you can use the special menu that opens when you click on the button . Here 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 . When this item is selected, Far Manager will start , and the cursor will point to:
    1. File opened in the editor - if you accessed the menu from the editor;
    2. 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, because My Far Manager is configured to work with a different window size.


    In order to open the window of the usual size, you will 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 under the name 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 the usual dimensions for me.


    Note


    Visual Studio uses cmd.exe to run CMD scripts , invoking 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 quotation marks and with script completion codes!

    Calling the External Tool from the context menu


    Ok, we got a workable tool, now we can start adding goodies - for example, add the Open Containing Folder in FAR call to the Solution Explorer context menu .

    This requires:
    1. Open the Customize window ( Main Menu > Tools > Customize ... ).
    2. Go to the Commands tab .
    3. In the Choose a menu or toolbar to rearrange section, select Context menu , and then select Project and Solution Context Menus | Item .

    The next step is to select the appropriate position for the new menu item. I decided to place it next to the Open Containing Folder item .


    Now you need to insert a new menu item into the selected position, the Add Command button is designed for this , which brings up 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 to launch External Tools can only be identified by the serial 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 Solution Explorer context menu :


    Additional Information


    Additional information on working with External Tools can be obtained on MSDN:
    1. External Tools in Visual Studio
    2. Arguments for External Tools

    Also popular now: