PathFinder - A Visual Studio add-in

Posted : Saturday, 26 September 2009 10:47:28

I spend most of my time working in my office at home and communicating with colleagues via some form or other of instant messenging protocol. Aside form the inevitable miscommunications that can occur from time to time (generally solved with judicicous use of smileys ;-)) I find this method of working to be quite productive. I'm less prone to distractions and feel better able to focus on a task.

One situation that arises fairly frequently when discussing with a colleague a particular aspect of a project we are both working is that I find myself making use of the rather handy "copy full path" feature of the visual studio tabbed environment (if you don't know what I mean, right click a tab and its one of the context menu options). Typically I'll paste the path into the IM window such that whoever I'm talking to can identify and open the file in question and we can look at the same code and discuss the best course of action etc.

While the "copy full path" feature is undoubtedly handy, it can sometimes be a bit of a chore to examine the path in the IM window, trace the path via the project structure and locate the file. It occurred to me that a handy feature of Visual Studio would be to take a supplied path and search through the current solution to find any matches for that path. An important consideration when designing this project was that local paths to the same file on each computer may (and usually does) vary so the add-in must be able to account for different physical file locations.

So this is my first foray into the world of Visual Studio Add-in development

The add-in

To Begin, create a new visual studio project and select "Visual Studio Add-in" template which can be found under "Other Project Types -> Extensibility", you will then be presented with a multi-step wizard. The first few steps of the wizard are fairly self explanatory, at step 4 however you will need to select add-in options.

step 4 of add-in wizard

Selecting the first checkbox will add a new item under the tools menu of the main visual studio toolbar. Follow the rest of the wizard accepting the defaults at each stage to create a new add-in project.

A visual studio add-in project is much the same as any other aside from a few subtle differences. For this add-in I only needed to alter the default auto-generated code in a couple of places. First I changed the default icon from the smiley face icon (in my opinion this looks pretty cheap) to something more appropriate. There are a number of stock icons that you can chose from - I spent a considerable amount of time trying to get a custom bitmap for my add-in but could not get it to work properly, according to the official documentation this can be acheived by adding the custom bitmap to a satellite assembly. I have read rumours that VS 2010 will do away with this seemingly over-engineered procedure so lets hope on that one! But I digress, I changed from the default smiley icon to the design mode icon by changing the following autogenerated code:

   77         //Add a command to the Commands collection:

   78         Command command = commands.AddNamedCommand2(

   79             _addInInstance,

   80             "PathFinder",

   81             "PathFinder",

   82             "Executes the command for PathFinder",

   83             true,

   84             59,

   85             ref contextGUIDS,

   86             (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled,

   87             (int)vsCommandStyle.vsCommandStylePictAndText,

   88             vsCommandControlType.vsCommandControlTypeButton);


   90         //Add a control for the command to the tools menu:

   91         if((command != null) && (toolsPopup != null))

   92         {

Post a comment Sharespacer Download source

  • (This will not appear on the site)