This is a follow up question from Team Foundation Server: Getting the Changeset Id from PolicyBase object
I would like to run some code when I check-in occurs. The answer in the linked question above pointed me at this page on MSDN.
I didn’t fully understand the explanation on the page and I’m not sure where the check-in event handler would be run.
Should this be in an application that is run on every client machine or is this something that needs to be run on the actual TFS server?
I need to make sure the check-in event handler code is run for every check-in regardless of which client made the check-in.
I tried downloading the sample code available on that Microsoft page but it does not work.
I can connect to the TFS Server. When I click on the “Get List of Registered Events” button, the left hand list box populates with 13 items all with the name
Microsoft.TeamFoundation.Server.RegistrationEntry
As soon as I click on one of the items, I get a TypeLoadException with the message
Could not load type ‘Microsoft.TeamFoundation.Server.Subscription’ from assembly ‘Microsoft.TeamFoundation, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’
(Strangely it seems like this is referencing the VS2010 version of the assembly even though it is the VS2008 version that I have linked to the project).
What am I doing wrong here?
Library References
I always found it a pain to try use the TFS2008 libraries instead of the 2010 ones once they were installed. You may be able to change the reference to use a specific version of the DLL, however there shouldn’t be any hard using the TFS2010 ones instead as they are backwards compatible.
Event Subscriptions
For TFS2010 it’s easiest to drop a custom DLL in c:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\Web Services\bin\Plugins these are fairly simple to write and just involve implementing ISubscriber for CheckinNotification.
For TFS2008, or if you like in TFS2010, you need to use the SOAP webservices (or the bisubscribe.exe tool) to subscribe to events and have a webservice yourself for tfs to push events to. This is a much harder way to subscribe to events so if you can use the Plugin method instead I would recommend it (Although it can be more robust and is better for load distribution).
TFS Deployer is a open source project that runs as a windows service and receives event notifications via the SOAP service. It contains a library (which may be reusable) that appears to have some code in it for receiving checkin events
Using subscriptions you only need one copy of the application picking up events and handling them, it can be on the TFS server (has to be if you are using the plugin method) but can be on another machine when using SOAP subscriptions.
Check-in Policies an Alternative Answer?
Depending on exactly what you’re coding, you may be able to write a check-in policy instead. This needs to be installed on all client machines and won’t be supported by all the different clients (eg eclipse) but it may suit your needs. The example I gave earlier of the tool to support embedded workitem codes in checkin comments also comes with a check-in policy to perform other checks