How can I get the latest change-set number via TFS API? Could you give me an example?
Find a changeset by IDIn Source Control Explorer, press Ctrl + G. The Go to Changeset dialog box appears. Type the number of the changeset and choose OK. If you don't know the number, choose Find.
Accessing TFS/VSTS through the REST API To setup the personal access token, login to TFS/VSTS and go to your profile (icon in the right top corner), then click on the security link. You can then have access to view, add and expire tokens.
Take searching for a changeset in Visual Studio's TFS Source Explorer. Luckily if super easy to do! When you're in the Source Explorer, simply press Ctrl + G and the Find ChangeSet dialog will appear. From here you can type the changeset number and press OK.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With