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:
- In Visual Studio 2008 go to Tools -> External Tools…
- 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)
- Click Ok.
- Right-Click on the toolbar -> Click Customize…
- Select the Toolbars tab -> Click New -> (Enter a suitable name e.g. Scripts)
- Select the Commands tab.
- 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)
- Drag-and-Drop “External Command 3″ and/or any other external commands you created previously.
- Click Close (At this point the button should automatically be renamed to the title of the external command they are linked to).
- Drag the new toolbar group to where you want it on the toolbar and enjoy 🙂