Wednesday, November 18, 2009

Visual Studio Team System & Shelve Sets

Another often overlooked (or at least under appreciated) feature of Visual Studio Team System is Shelve Sets. A Shelve Set is a way to partially commit your code to the server without affecting anyone else.

Using Shelve Sets is really simple. Go to the Pending Changes window, select the files you would like to ‘shelve’, enter a description in the Comments area, optionally select any work items you want to associate the Shelve Set with, and click the Shelve button in the Pending Changes toolbar.

A new window will appear asking you to give the shelve set a name, choose whether you want to preserve your changes locally (which will undo any changes made to the selected files locally), and if you want any check-in policies evaluated.

Once the shelve set is created, you will now have a copy of all the changes you selected on the server. Like a traditional bookshelf, you can have multiple shelve sets stored on the server.

Now that your changes are on the server, anyone else can search for and pull down these changes to their workspace.

Here are a few of the common shelve set uses:

  • Performing a check-in policy evaluation (such as Code Analysis, StyleCop, etc.) without actually committing the code. This is a nice sanity check now and then while you are writing your code instead of waiting until the end.
  • Isolate changes for different work items. We’ve all been working on a new feature when we get an ‘urgent’ bug that requires us to stop what we are doing and fix it. Create a shelve set for your current changes (removing the checkmark for the preserving your changes) and you now have a completely clean workspace for working on the ‘urgent’ bug.
  • Code reviews. Create a shelve set of your code for another team member to pull down and review on their system. Working with and exercising the code on their system allows for a much better code review than simply looking at a print out of the code or the end result.
  • Code Handoffs. Heading out on vacation for a while or assigned to another team? Create a shelve set of your current progress and someone else can pull it down and start continue to work on it.

Best Practice

The best use that I’ve found for using shelve sets is to backup your current progress before you go home every night (I call this shelve set WIP for Work In Progress). A lot of things can happen between the time you leave work at night and come back in the morning. Roof leaked, power surge, failed hard drive, latest virus outbreak, etc. If you’ve created a shelve set on the server before you went home, your covered. You can use another machine to pull down what you were working on. Just be sure to remove the check for preserve pending changes locally so that any files you have locked are released, allowing you to check them out on another machine without assistance from a TFS Administrator.

No comments: