Adding Custom Toolbar Buttons To VS2008

So you’re a smart cookie and you’ve written yourself some scripts to build your DAL or perhaps to deploy or package for a different environment; However, when you want to run said scripts you have to open up a command window, navigate to the working folder and run the scripts. Not only is this a pain and waste of valuable time, it also inevitably results in a taskbar full of command prompt windows! Well, there is a quick and easy way to add custom buttons to your Visual Studio 2008 toolbar which will fire off your scripts and display the results in the output window.

The first step is to ensure you have a consistent approach to how your projects are set up in order to run your scripts. After all, you don’t want to have to create a unique toolbar button for every single application you’re developing. One simple approach to this is to create a batch file of the same name (e.g. GenerateDAL.bat) for each application which can then call of to project specific actions. Once you have a consistent pattern to your projects your custom toolbar buttons will become much more useful and save you lots of time.

Steps for creating a custom toolbar button:

  1. In Visual Studio 2008 go to Tools -> External Tools…
  2. Click Add -> (Complete the form)
    Title: (Name of the script e.g. Generate)
    Command: (Location of script e.g. $(SolutionDir)CodeSmithCode.Generate.cmd if your script is in the folder ‘CodeSmith’ of all your project)
    Arguments: (Leave this one empty if you wish)
    Initial directory: (Location of script or the folder level from which you would usually call your script e.g. $(SolutionDir)CodeSmith)
    (Check Use output window to display results in the output window)
  3. Click Ok.
  4. Right-Click on the toolbar -> Click Customize…
  5. Select the Toolbars tab -> Click New -> (Enter a suitable name e.g. Scripts)
  6. Select the Commands tab.
  7. Under Categories scroll down and select Tools -> Under Commands scroll down to External Command 3 (this assumes you only have to default 2 commands in Visual Studio — if you have more than the external command number will match the order of your external commands list)
  8. Drag-and-Drop “External Command 3″ and/or any other external commands you created previously.
  9. Click Close (At this point the button should automatically be renamed to the title of the external command they are linked to).
  10. Drag the new toolbar group to where you want it on the toolbar and enjoy 🙂