Wednesday, June 11, 2008

How to get latest changeset number from TFS within NAnt

I had hard time getting this up and running so thought of sharing here. Might be useful to someone.

This guy has excellent post on this topic, here

Its very simple and self explanatory, so I don't think I have to give any thing more. Just ignore other target and focus only on Version target

The real gut behind this comes from the C# code, embedded within NAnt task

Here is the unchanged copy of code snippet, in case you don't want to navigate way.

public static void ScriptMain(Project project)
{
project.Log(Level.Info, "Connect to " + project.Properties["tfs.server"]);
TeamFoundationServer tfs = new TeamFoundationServer(project.Properties["tfs.server"]);

// Get a reference to Version Control.
Type type = typeof(VersionControlServer);
VersionControlServer versionControl = (VersionControlServer)tfs.GetService(type);

project.Log(Level.Info, "get changesetId for " + project.Properties["tfs.fullpath"]);
IEnumerable changeSets = versionControl.QueryHistory(project.Properties["tfs.fullpath"], VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 1, true, false);
int latestChangesetId = 0;

// there is only one
foreach(Changeset c in changeSets)
{
latestChangesetId = c.ChangesetId;
}

project.Log(Level.Info, "ChangesetId is " + latestChangesetId.ToString());
project.Properties["project.version.revision"] = latestChangesetId.ToString();
}

1 comment:

Anonymous said...

Witam serdecznie!

Szukam i szukam i znalezc przyczyny nie moge... problem mam nastepujacy: moja strona ([url=http://www.nieruchomosci-pila.net]Piła mieszkania[/url]) raz sie otwiera innym razem z kolei dostaje jakies dziwne komunikaty albo w ogole przegladarka twierdzi, ze takiej strony nie ma. Do tego na niektorych kompad pod internet explorerem wyswietla mi sie wyszukiwarka binga - i tam pojawia sie na pierwszym miejscu link ktory... zazwyczaj otwiera strone. Macie jakies pomysly?

Bede wdzieczny za wszelkie propozycje, nagroda - szczegoly na PW!