Skip to content

Instantly share code, notes, and snippets.

@house9
Created August 19, 2010 19:33
Show Gist options
  • Save house9/538692 to your computer and use it in GitHub Desktop.
Save house9/538692 to your computer and use it in GitHub Desktop.
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;
}
string revision = String.Empty;
if(latestChangsetId > 65534)
{
// use the last 4 numbers only
revision = latestChangesetId.ToString().Substring(latestChangesetId.ToString().Length - 4, 4);
}
else
{
revision = latestChangesetId.ToString();
}
project.Log(Level.Info, "ChangesetId is " + latestChangesetId.ToString());
project.Log(Level.Info, "Revision will be " + revision);
project.Properties["project.version.revision"] = revision;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment