Thursday, 12 July 2007

Using the changeset

In one of my previous posts, I showed an article which allows you to generate an automatic build number based on Date/Time. This generates a huge number (which is a bit of pain to work with).

In this post I will show you how to modify that code to modify that task to use the changeset number as the build number (which is virtually incremental in a CI environment).

Simply reference the Team Foundation Server Assemblies required for the following using statements:

using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

And now simply use this little method to get the changeset number:

private int GetLatestChangeSetId()
// Get a reference to our Team Foundation Server.
string tfsName = @"http://myserver:8080";
TeamFoundationServer tfs = new TeamFoundationServer(tfsName);
// Get a reference to Version Control.
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
int latestChangesetId = versionControl.GetLatestChangesetId();
return latestChangesetId;

No comments: