Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the latest change-set number via TFS API

Tags:

c#

api

tfs

How can I get the latest change-set number via TFS API? Could you give me an example?

like image 428
orange Avatar asked Apr 20 '12 16:04

orange


People also ask

How do I find my TFS changeset number?

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.

How do I access TFS API?

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.

How do you change sets in TFS?

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.


1 Answers

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.

like image 76
Nock Avatar answered Oct 20 '22 19:10

Nock