Jan 072012
 

Microsoft provides two TFS administration tools as standard:

Name Source What TFS admin jobs does it do best?
TFS Admin Console TFS installation Configure the installation of TFS
Team Explorer Visual Studio or Team Explorer installation Team project settings such as areas and iterations, source control settings, security and groups. Development work such as build customisation.

 

Good as these are, there is much they don’t do well (or at all). I have found the additional tools below very helpful.

Name Source What TFS admin jobs does it do best?
TFS Power Tools Visual Studio Gallery Adds teams node, tools for customising work item process templates, backup/restore wizard, alerts explorer, test attachment cleaner etc
Team Foundation Sidekicks Attrice Corporation View and undo check-outs, manage workspaces etc
TFS Administration Tool CodePlex Manage security across different products in a TFS deployment: TFS, SharePoint, and Reporting Services
Inmeta Build Explorer Visual Studio Gallery Organise build definitions into folders
TFS Area Import/Export Tool Neno Loje Copy areas and iteration between team projects (great if you have a sandbox or training team project)

 

There are many other add-ins and tools out there, but these are the ones I use with some frequency. I’ll update the table if I add others to my regular TFS toolbox!

 Tagged with:
Jan 052012
 

The Visual Studio Alerts Explorer that comes with TFS Power Tools provides a great GUI for configuring email alerts on all kinds of events generated by TFS. However, it is not problem-free.

A little while back I came across a bug, in Alerts Explorer or the TFS events system, which had a very irritating effect – spam! It took a good while to diagnose but a fairly simple workaround was found. Here’s the scenario…

Imagine you want to receive an email whenever a work item is assigned to you – a very common requirement. The obvious way to set it up is like this:

This alert definition should send an email to Joe Bloggs whenever a work item is assigned to him, except for when he assigned it to himself. And it will do exactly that, most of the time. Unfortunately it will also send an email when a link is added to a work item already assigned to Joe Bloggs, with no other changes made at the same time. Imagine that another user is linking a handful of work items, one at a time, to another work item that is with Joe Bloggs. Poor old Joe will receive one email for every link added!

To diagnose this issue it’s necessary to understand the TFS eventing system. It basically works as follows:

  1. Every time an event happens (the “WorkItemChangedEvent” in this case) an XML document is generated by the TFS Eventing system.
  2. TFS sends the XML to all subscribers to that event, which in this case includes the Alerts system.
  3. The Alerts system applies the filter defined for each alert to the event XML to identify which alerts are relevant.
  4. For each alert match, an XSLT transformation is applied to convert the XML to HTML, and an email is fired off.

So far, so good. So why does this alert also fire off emails when the only thing changed is a work item link? There are two parts to this puzzle. The first is the Filter Expression for the alert. Alerts Explorer handily exposes the underlying filter generated by the GUI on a second tab:

This is actually a partial XPath expression, which is applied against the event XML. If there’s a match then the alert is sent. This filter amounts to a query that (to paraphrase) says CoreFields/AssignedTo/OldValue is not “Joe Bloggs” and CoreFields/AssignedTo/NewValue is “Joe Bloggs” (the ChangedBy field isn’t part of the problem, so I’ll ignore it).

The second part of the puzzle is the event XML itself. Unfortunately this is much more difficult to come by than the Filter Expression. There are various methods by which you could get at the XML, but I found a simple solution was to replace the XSLT transformation which would normally generate a nicely formatted HTML email message with one that simply spits out the source XML as HTML, so you can see it in the resulting email. Of course you shouldn’t do that in a production system, as your users are unlikely to appreciate emails containing raw XML!

Quick instructions on how to replace the alert XSLT:

  1. On the TFS application tier go to this folder (or equivalent) – C:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\TFSJobAgent\Transforms
  2. Rename WorkItemChangedEvent.xsl to WorkItemChangedEvent.xsl.bak
  3. Download XMLToHTMLVerbatim.xsl (Copyright 2002 Oliver Becker) copy it into the folder and rename to WorkItemChangedEvent.xsl
  4. Edit and save work items and inspect the resulting emails (there may be a two minute delay as alerts are queued)

With that in place you can see that the XML generated when only adding links to a work item looks like this:


<WorkItemChangedEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 ...
 <Subscriber>UK\JoeBloggs</Subscriber>
 ...
 <ChangeType>Change</ChangeType>
 <CoreFields>
 <IntegerFields>
 <Field>
 <Name>ID</Name>
 <ReferenceName>System.Id</ReferenceName>
 <OldValue>0</OldValue>
 <NewValue>192</NewValue>
 </Field>
 <Field>
 ...
 </IntegerFields>
 <StringFields>
 <Field>
 <Name>Work Item Type</Name>
 <ReferenceName>System.WorkItemType</ReferenceName>
 <OldValue />
 <NewValue>Bug</NewValue>
 </Field>
 ...
 <Field>
 <Name>Assigned To</Name>
 <ReferenceName>System.AssignedTo</ReferenceName>
 <OldValue />
 <NewValue>Joe Bloggs</NewValue>
 </Field>
 <Field>
 <Name>Changed By</Name>
 <ReferenceName>System.ChangedBy</ReferenceName>
 <OldValue />
 <NewValue>Fred Smith</NewValue>
 </Field>
 ...
 </StringFields>
 </CoreFields>
 <AddedRelations>
 <AddedRelation>
 <LinkName>Affects</LinkName>
 <WorkItemId>358</WorkItemId>
 </AddedRelation>
 </AddedRelations>
</WorkItemChangedEvent>

Even though the assignment has not changed – the work item has been with Joe Bloggs the whole time – the OldValue for AssignedTo is empty. The NewValue correctly says Joe Bloggs, so the filter is met and an alert sent! The eventing system detects the change but the XML has inaccurate values, so it appears that a different change occurred (I have reported this on Microsoft Connect).

The workaround (which is thankfully much simpler than the investigation) is to modify the alert definition to also reference the XML’s ChangedFields. These fields are not populated in the example above, but are present in every other type of work item change. It seems a little odd that Alerts Explorer does not reference these fields when you use the Changes To or Changes From operators, because it does when you use the Changes operator. So all you need to do is add a Changes operator to the alert definition like so:

The filter expression now includes AssignedTo within ChangedFields as shown below, ensuring you don’t get the alert unless that field really has changed.

I suspect the fix for this is a change to the TFS eventing system to properly populate the OldValues, or a change to Alerts Explorer to reference ChangedFields when using the Changes To/From operator (or both).

Although it’s painful to debug this issue, it gives an interesting insight into the system and hopefully this post will help others figure out why TFS is spamming them!

Jan 032012
 

TFS has a great (but not perfect) events and alerts system – you can be sent emails about work item changes, source control check-ins and build completion. TFS Power Tools adds Alerts Explorer to Visual Studio, which is a must-have for configuring alerts as the built-in Project Alerts is very basic.

Alerts Explorer allows very sophisticated filters to be set up, but that power can be confusing. I have found that in a development team lead role just two special alerts provided the oversight I needed. Here’s how to set them up.

Alert 1: Check-in Policy Override

Check-in policies (along with folder security) are invaluable for source control management – they can enforce check-in comments and linked work items, and prohibit specific file types being checked-in. However, users can simply override the check-in policy! In one way this is helpful, because it allows work to continue past an overly-restrictive policy, but in every other way it’s madness – people can ignore your carefully constructed policies whenever they like.

Fortunately there is a good compromise – you set up an alert telling you when the check-in policy has been overridden. That way, the user can override the policy if they think they really must, but you get to review what happened and take action if necessary. I found that simply telling people that you get an alert when the policy is overridden was a sufficient deterrent 99% of the time.

This alert is a slight modification of a template that comes with the TFS Power Tools. Note that all source control users must have the power tools installed if you are using any of the check-in policies that come with the power tools, or you will receive an alert every time they check-in (which is quite useful, as you can then tell them to install the power tools!)

Alert 2: Build Failure

The Build Notifications tool that comes with Visual Studio is OK, as it generates system tray alerts that are near-synchronous with build completion. But it’s not much help if a build failed an hour ago or overnight. An email alert can cover this instead.

Note that I have not simply chosen StatusCode = Failed as I also want to be alerted on builds that are “partially successful” i.e. that have test failures. I’ll give users the benefit of the doubt on Stopped builds and assume that builds are only stopped for valid reasons. You may decide differently for your team.