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.

Thursday, November 05, 2009

Visual Studio Team System and Cloak

When I first started using Visual Studio with TFS for a new position, I started reading the Team Development with Visual Studio Team Foundation Server guide since I had never used it before. I got about half-way though it before I started the new job and became so busy I no longer had time to finish reading it. Had I kept reading, I would have found a piece that talked about the “cloak” menu item when viewing your Source in the Source Control Explorer.

Say you have a root-level folder in Source Control with the following structure…

  • ProjectA
    • MainLine
  • Branches
    • v1.0
    • v1.0-SP1
    • v2.0

Rather than create a separate workspace mapping for each version, you would create a single workspace at the top level. This makes it easy to keep everything in sync by just performing a Get Latest operation on the ProjectA node and you will instantly have the latest for everything.

There are a couple of problems with the approach. First, what if you are currently only working on the MainLine version? Do you really want the previous 3 versions stored on your disk? If the project is small this might not add up to much, but if it’s a major project this can easily consume tens of gigabytes of space.

The second problem comes into play when performing a Get Latest operation. With everything mapped from the root-level node, TFS needs to contact the server and compare your workspace with the server in order to determine what has changed and what needs to be updated. If you are currently working only on the MainLine branch, do you want or care about the changes in another branch? (Veteran coders will know that you can perform a Get Latest on specific folders, but this sometimes leads to performing a Get Latest too low in the tree and missing required dependency updates from higher up).

The solution is to create a root-level workspace mapping as stated above. When you are prompted to perform a Get Latest, say no. In the Source Control Explorer window, right-click on any folder you don’t want included and select the Cloak menu item. This prevents the folder from being included in your workspace mapping and prevents it from being downloaded and subsequently updated every time you perform a Get Latest.

In our example, someone only working on the MainLine branch would cloak the Branches folder. If someone needs to be working on the MainLine as well as a previous version (like a Service Pack), they could cloak the individual branch folders they don’t care about.

Nice!