3

I want to get date of changeset. The TFS SDK has much reference. Which reference and class do I need?

SetFreeByTruth
  • 819
  • 8
  • 23

1 Answers1

10

One of the best resources I've found on the TFS API is this series of blog posts: http://blogs.microsoft.co.il/blogs/shair/archive/tags/TFS+API/default.aspx

In this case, there's nothing explicitly about getting changeset information (that I saw) but there are a couple of other source-control related posts. From there you'll see that you need to start by getting a VersionControlServer instance, and the MSDN page for that class should get you the rest of the way: call GetChangeset to get a particular Changeset object, which in turn has a CreationDate property.

(If you don't actually know the changeset number you want, you can use methods like QueryHistory to get changeset lists for particular paths in the source control database.)

var collectionUrl = "http://tfsserver:8080/tfs/DefaultCollection";
var tpc = new TfsTeamProjectCollection(collectionUrl);

var vc = tpc.GetService<VersionControlServer>();

// Get changeset #1234
var cs = vc.GetChangeset(1234);

// Get the last changeset checked into TFS by anyone.
var cslatest = vs.GetChangeSet(vs.GetLatestChangesetId());    

// Get a list of all changesets for the $/MyProject/Main branch
var cslist = vc.QueryHistory("$/MyProject/Main", null, 0, RecursionType.Full, 
    null, null, int.MaxValue, false, false);
Michael Edenfield
  • 28,070
  • 4
  • 86
  • 117
  • i gei the teamproject , i can use teamproject.name to get project's name. but how can i get the changeset?? Getchangeset(int changeset),what's mean the "int changeset" ??? – user1536577 Jul 19 '12 at 06:17
  • Changesets are assigned numbers that are unique across the entire system;. The value is just the number you see when you look at a changeset in History view or whatever -- the changeset ID. You need to get a reference to the version control server for your team project. I'll add example code to the answer. – Michael Edenfield Jul 19 '12 at 13:47
  • @MichaelEdenfield One (pedantic) correction: changesets and unique by *team project collection* (and one system can have many project collections). – Richard Jul 19 '12 at 14:28
  • That's true; I migrated up from a TFS2005 and have never actually seen one with multiple collections so I still tend to associate a TPC with an old TeamServer :\ – Michael Edenfield Jul 19 '12 at 14:31
  • hi. when run var cs = vc.GetChangeset(1234); it generate a error, You are not authorized to access xxxxxxxxxxx.... but i have get project's name before it. why i am not authorized to access ........ – user1536577 Jul 20 '12 at 01:51
  • Permissions on TFS are very complex; source control has its own set of access controls that are independent of the basic project information. It appears that you just don't have access to the files included in whatever changeset #1234 is. – Michael Edenfield Jul 20 '12 at 02:01
  • yeah,but i can see changeset and view history through source control of team explorer in vs2010, so i should have right to access..... – user1536577 Jul 20 '12 at 02:07