Opening a VS item's directory in Explorer

I use TortoiseSVN as my SVN client, but it is not integrated into Visual Studio like AnkhSVN and others. This generally suits the way I like to work, but occasionally it would be nice to right click on a new class and pick “Add to SVN”, or have an easy way of doing an SVN move. I have recently started using a simple way of accessing these features, without installing a VS-integrated client, by providing a shortcut to opening a Visual Studio item’s folder in Windows Explorer where we can use all our standard TortoiseSVN functionality.

UPDATE 2007-09-24: The functionality provided by the following steps is very similar to right-clicking on tab of an open file, and selecting “Open containing folder”, which I admittedly only just noticed*. I have left this example online for two reasons. First, the method below offers a bit more functionality, as it also works for files selected in the Solution Explorer. Secondly, the general approach described is a really useful technique for easily extending VS. For example, I remember seeing a screencast of configuring Subsonic’s SubCommander as an external tool in VS to generate your DAL and script your database with a single button click.

From Visual Studio 2005 (similar steps should work for 2008/Orcas too):

  1. Go to the Tools menu and select External Tools…
  2. Click on the Add button
  3. Set the executable to your Windows Explorer path (C:\WINDOWS\Explorer.exe on my PC).
  4. Set the arguments and initial directory to "$(ItemDir)". Not sure if the quotes are needed incase you have spaces in your paths, but they don’t seem to hurt.
  5. Give it a title, such as Open in E&xplorer. The & just designates the menu accessor key, which is x in this case. – you can leave it out if you like.
  6. Note which number your external tool is in the list – in the screenshot mine is #7 (1-based counting here). This is only for if you want to create a menu button for this external tool.
  7. Click OK

Screenshot of External Tools dialog.

You can now select an item in the solution explorer, or just use the file you are currently editing, and go to Tools –> Open in Explorer to open the file’s folder. Now you are back in Tortoise country, and can add the file to SVN.

You can make this even easier by setting up a menu button for the external tool:

  1. Right-click on one of your menu bars and select Customise (ok, it says Customize, but I can correct the spelling can’t I? :) )
  2. From the Commands tab, select the Tools category, and then External Command {xx}, where {xx} is the number you carefully noted in step 6 of creating the external tool.
  3. Drag and drop the command on to the menu bar of your choice.
  4. Customise the button’s appearance as required. I right clicked on the View –> Solution Explorer menu item and selected Copy Button Image, then right-clicked on my button and used Paste Button Image to get a purdy icon. I also hid the text description so it takes less room on my menu bar.
  5. Click Close on the customisation dialog.

You can now select a file, click the icon, and voila, instant Explorer. Ok, so this sounds largely pointless, but it does really help me to quickly switch between Visual Studio and TortoiseSVN.

* There seems to be quite a lot of cool crouching-tiger-hidden-features in VS 2005 (i.e. features that are not very discoverable). Some of the things I love about Resharper are present (mostly in simplified form) in standard VS 2005, but they are easier to discover (and generally easier to use and work better IMHO, YMMV) in Resharper.