Search code examples
c#tfs-sdk

Get the latest check in number (latest changeset id)


Is there a way to get programmatically latest changeset version in general.

It's fairly easy to get changeset id for certain file :

var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://my.tfs.com/DefaultCollection"));
        tfs.EnsureAuthenticated();
        var vcs = tfs.GetService<VersionControlServer>();

and then call GetItems or QueryHistory, but i would like to know what was the last checkin number.


Solution

  • You can do it like this:

    var latestChangesetId =
        vcs.QueryHistory(
            "$/",
            VersionSpec.Latest,
            0,
            RecursionType.Full,
            String.Empty,
            VersionSpec.Latest,
            VersionSpec.Latest,
            1,
            false,
            true)
            .Cast<Changeset>()
            .Single()
            .ChangesetId;