Wednesday, February 11, 2009

Use Visual Studio 2008 SDK to customize TFS


Recently I got a chance to assist someone in the other project of my client to generate a report from TFS. He needed a report of all the details of the changeset in certain period of time. I managed to write some sample code for him with Visual Studio 2008 SDK 1.1 which provides API to query TFS history and get the change-set details.

The code is in C#. The test was very successful; I could query the history; then I got changeset list; then I used the changesetid to get all the objects (change instances). There are two main methods you can find in the attached solution. –QueryHistory [1] and GetChangeset[2].

[1]: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.queryhistory(VS.80).aspx
[2]: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.getchangeset(VS.80).aspx

Sample code:

        private static IEnumerable QueryHistory()
{
TeamFoundationServer tfs = new TeamFoundationServer(tfsName);

// Get a reference to Version Control.
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
string path = @"$/YOUR-TEAM-PROJECT-NAME";
VersionSpec version = VersionSpec.Latest;
int deletionId = 0;
RecursionType recursion = RecursionType.Full;

string user = "YOUR-USER-NAME";
// VersionSpec versionFrom = VersionSpec.ParseSingleSpec("115894", "mahesh_lambe");
//keep it 'null' for first version
VersionSpec versionFrom = null;

// VersionSpec versionTo = VersionSpec.ParseSingleSpec("109014", "mahesh_lambe");
//keep it 'null' for latest version
VersionSpec versionTo = null;

int maxCount = Int32.MaxValue;

bool includeChanges = true;

bool slotMode = true;

bool includeDownloadInfo = true;

IEnumerable enumerable = versionControl.QueryHistory(path, version, deletionId, recursion, user, versionFrom, versionTo, maxCount, includeChanges, slotMode, includeDownloadInfo);

return enumerable;
}


        // Get a reference to our Team Foundation Server.              
private static String tfsName = @"http://YOUR-TFS-SERVER-NAME:8080/";

internal static Changeset GetChangeset(int _changesetNumber)
{
TeamFoundationServer tfs = new TeamFoundationServer(tfsName);

// Get a reference to Version Control.
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
Changeset ch = versionControl.GetChangeset(_changesetNumber, true, true);

Console.WriteLine(ch.ToString());
return ch;
}

No comments:

Be A Developer That Uses AI

Developers will not be replaced by AI, they'll be replaced by developers that use AI. Generative AI tools are revolutionizing the way de...