Reputation: 740
How can I get the latest change-set number via TFS API? Could you give me an example?
Upvotes: 7
Views: 7049
Reputation: 6609
Here you go:
TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, true);
tpp.ShowDialog();
var tpc = tpp.SelectedTeamProjectCollection;
VersionControlServer versionControl = tpc.GetService<VersionControlServer>();
var tp = versionControl.GetTeamProject("MyTeamProject");
var path = tp.ServerItem;
var q = versionControl.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, null, VersionSpec.Latest, VersionSpec.Latest, Int32.MaxValue, true, true, false, false);
Changeset latest = q.Cast<Changeset>().First();
// The number of the changeset
int id = latest.ChangesetId;
QueryHistory is invoked with the path in the VersionControl of your TeamProject, we want the history from the latest to the latest changeset, the whole bunch of parameters left are pretty default in your case.
Upvotes: 7