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; }