Click here to Skip to main content
14,870,687 members
Articles / Visual Studio / Visual Studio 2010
Posted 3 Aug 2011


17 bookmarked

Bazaar in Visual Studio: External Tools

Rate me:
Please Sign up or sign in to vote.
4.71/5 (7 votes)
16 Aug 2011CPOL9 min read
How to integrate Bazaar into Visual Studio using the IDE's External Tools


Bazaar is a modern, distributed version control system. As of this writing, there are no Bazaar add-in packages that provide integration with Visual Studio. This article will show how to integrate Bazaar into the Visual Studio Integrated Development Environment (IDE) using Visual Studio's External Tools.


TortoiseBzr (see image below) is a Graphical User Interface (GUI) that provides integration of Bazaar into the Windows Operating System's file manager, Explorer (not to be confused with Internet Explorer). The default Bazaar Windows Installation includes TortoiseBzr, Python, and Bazaar. This is the recommended installation. During the installation, choices will be presented for which add-ins, languages and options you wish to install. Skip languages you do not speak, but install everything else. If you do not install TortoiseBzr, this How-to will provide unsatisfying results. You can still configure external tools to use Bazaar, but all the output will go to the text-only based Output Window of Visual Studio. When we configure the Status command, an example will be provided that demonstrates how this can be done for other commands, but with similar output results.


TortoiseBzr Explorer

Bazaar001.png A quick Google search of online forums will reveal many arguments against installation of Tortoise due to the sluggish updates in Explorer that render the information unreliable. Although it is true that Tortoise integration with explorer is sluggish, we need it here for the Graphical User Interface it provides. In this area, performance is quite acceptable. (Status within the Tortoise Explorer Window is also quite adequate. Only the check-mark and exclamation icons on files and folders seen when you browse through My Documents are slow. See icons to the right, showing one folder with pending changes, and one file that is marked up-to-date.)



Product instructions on how to install Bazaar and how to configure TortoiseBzr are quite adequate. Setup of a repository (or repo) depends on a desired workflow for managing software changes and is beyond the scope of this article. For information on how to configure the various workflow options and create a repository, shared or otherwise, read the Bazaar User Guide. Setup and installation is covered there in sufficient detail that little more can be offered here — this article will focus on integration.

Code Bazaar Menu

Open Visual Studio, right click on any of the menu items, and choose Customize.... When the Customize Dialogbox opens, select the Commands Tab. Along the right, you'll see a series of buttons, including the Add New Menu Button. Click the Add New Menu Button, and a new menu item is added called New Menu. Select that menu and click the Modify Selection Button. Change the name to something more useful, like Code Bazaar.

Now look at the Menu Bar Dropdown at the top of the Commands Tab of the Customize Dialog. Menu Bar will be selected by default, but you can click the drop-down and browse through all available menus and menu commands. Select the newly created menu item to add commands to the menu. Click the Move Up and Move Down Buttons to change the location of the menu on the menu strip. By default, new menus insert at the top and appear before the File menu; however, for this article, the Code Bazaar Menu will be assumed to be just after the Debug Menu, as shown below:


Visual Studio's Menu Strip with Code Bazaar Menu added

With the newly added menu selected in the drop-down, click the Add Command Button, and the Add Command Dialog will appear with a list of Categories on the left. Browse for and select the Tools Category. The commands listed on the right will change to reflect commands available for that category. Add External Command 1 through External Command 11. Some of these are already configured with Microsoft tools. (Spy++, Create GUID, etc. move down as new external tools move up the list. If you prefer the existing menu commands where they are, adjust which External Commands are added to the Code Bazaar Menu.) When done, click the Close Button at the bottom of the Customize Dialog.


Customize Dialogbox with Code Bazaar Menu selected and External Tools Commands added

Next, locate and click the newly added menu to verify that the external commands are there. By default, commands not configured are disabled and have the default text of External Command and the command number. Click the Tools Menu, and about four from the bottom, click the External Tools Menu Command, and the External Tools Dialog will appear. Click the Add Button to add a new command to the bottom of the list.

External Tools

Start with a simple status command — choose Status for the title in the External Tools Dialog. The status command shows a list of items pending a commit for the current repository. Because of the simplicity of the command, the Bazaar command line tool is adequate, and the output results can be directed to Visual Studio's Output Window. The command, then, will be the Bazaar executable, which by default is located at C:\Program Files\Bazaar\ and called bzr.exe. For the command, type C:\Program Files\Bazaar\bzr.exe. (If you installed Bazaar to another directory, adjust this command accordingly.)

To run bzr.exe from the command line, you could generate a status list with C:\bzr status. The argument for a status listing, then, is status. The initial directory will be the directory where you opened the solution file. The Visual Studio Argument for our directory is $(SolutionDir), so type that into the Initial Directory. Finally, verify that the output will be directed to the Output Window by setting the Use Output Window Checkbox. Next, with the Status Command selected, click the Move Up Button until this is the first command in the list: External Command 1. The results, when complete, should be similar to those below:


External Tools Dialogbox showing status command configuration

Initial Configuration Test

More external commands are needed, but for now, click the OK Button and return to Visual Studio, click the Code Bazaar Menu, and verify that we have a Status Menu Command at the top. If you already have a Bazaar-managed solution open, and if there are changes pending since the last commit, the Status Menu Command displays a list of modified files. (See below.) If there are no changes, the output will be empty — this is not an indication of an error, only that there are no pending changes. (Modify a file, save the change, then try again to verify that Bazaar has identified a file has changed.)


Visual Studio's Output Window showing results of status command

Remaining Configuration

Most of the remaining commands use TortoiseBzr to provide a graphical interface. For the commit command (see below), open the External Tools Command of the Tools Menu, click the Add Button, and set the title to Commit. For the command, browse to the tbzrcommand.exe file (located at C:\Program Files\Bazaar\ if you installed TortoiseBzr to the default directory). For arguments, type --command=commit, and set the initial directory to $(SolutionDir). In this case, you can choose to use the Output Window, but this will only receive Python error and warning messages, which should be ignored (unless directed to look at them by Bazaar developers for troubleshooting). If you don't check the Use Output Window Checkbox, then a separate command window will open, and you'll want to close this when you close the TortoiseBzr window, so check the Close on exit Checkbox. When you are done, move the Commit Command up to just below the Status Command (External Command 2).


External Tools Dialogbox showing Commit Command configuration

Repeat this for All Differences, using tbzrcommand as the command, --command=diff for the argument, $(SolutionDir) for the directory, and check the Close On Exit Checkbox. For File Differences, the command becomes --command=diff --file=$(ItemPath). Here, the file is the one selected within the Solution Explorer Window of Visual Studio. For Log the command is --command=log, for File Log, the command is --command=log --file=$(ItemPath). For Add, the command is --command=add.

Reverting (restoring files to a previously saved state) is a little tricky. Revert a single file, and Visual Studio will display a warning that the file has been modified outside of the IDE (as desired). Reload the file in Visual Studio to complete the process. However, Visual Studio locks the solution file — to fully revert to the previous commit, including changes to the solution, close the solution and execute the command from TortoiseBzr or Bzr. Because of this limitation, a Revert Solution Command is not possible. For the Revert File command, the argument is --command=revert --file=$(ItemPath). This will only revert a single file (the one currently selected in Visual Studio's Solution Explorer Window), and it will only revert to the most recent committed version. (To revert to another version, use the Explore Command, described next.)

For Explore, the argument is --command=explorer. This is more a catch-all command, than a specific command. This will open TortoiseBzr's Explorer, the main interface — in essence, TortioseBzr running within Visual Studio. Finally, Bazaar allows the creation of tags on special revisions. These are simple commands and can be done directly in bzr.exe with output directed to Visual Studio's Output Window. To list the tags, the argument is tags and to tag the most recent committed revision, the argument is tag. In each case, direct the command to use the Output Window.

Below is an image of what you should see when you run All Differences with changes. Obviously, the specific changes will be different, but the differences popup should look similar. Notice the additional command window open between the differences popup and Visual Studio's editing window. If everything is setup correctly, this window should close when the differences window closes.


All Differences output


  • 16 August 2011: Updated Drop-cap for new CSS
  • 10 August 2011: Updated images to show $(SolutionDir)
  • 9 August 2011: Corrected text using $(SolutionDir) (Images pending)
  • 8 August 2011 Added image captions. Just realized I used $(ProjDir) incorrectly
  • 6 August 2011 First release


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) TenovaCore
United States United States
Rod currently works in The Burgh using .Net technologies to create Human-Machine Interfaces for steel-making furnaces. He has 7 years in the steel industry, and 12 years of experience working in the nuclear industry at Savannah River Site in Aiken, SC. He enjoys riding his Honda Goldwing through the winding Pennsylvania farmlands, and taking his Jeep offroad.

Comments and Discussions

QuestionReally like it, one suggestion / request Pin
Mike-MadBadger27-May-12 8:36
MemberMike-MadBadger27-May-12 8:36 
AnswerRe: Really like it, one suggestion / request Pin
knockNrod19-Jun-12 15:56
MemberknockNrod19-Jun-12 15:56 
QuestionExcellent! Pin
Amit Kumar Dutta4-Aug-11 7:48
MemberAmit Kumar Dutta4-Aug-11 7:48 
AnswerRe: Excellent! Pin
knockNrod4-Aug-11 10:42
MemberknockNrod4-Aug-11 10:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.