Get Latest ChangeSet History From Version Control

In this Post I will show how to get all changesets history from source control

  • Add new C# project.
  • Add these API’s references to the project
Microsoft.TeamFoundation.Client
Microsoft.TeamFoundation.VersionControl.Client


  • Connect To Team foundation server, add this code
TeamFoundationServer tfs;

VersionControlServer versionControl;

System.Net.NetworkCredential credential = new System.Net.NetworkCredential(”username”,”password”,”domain”);
string TFSServerPath = “http://tfs:8080“;
tfs = new TeamFoundationServer(TFSServerPath, credential);
tfs.Authenticate();
versionControl= (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

 

  • Create Method to get all changeset’s for specific dates.
//here you specify the exact time period you need to get the change set (from Date,to Date)
VersionSpec fromDateVersion = new DateVersionSpec(DateTime.Now.AddMonths(-6));
VersionSpec toDateVersion = new DateVersionSpec(DateTime.Now);
// using versionControl API you can query histroy for changes set for (specific,all) user
IEnumerable Data = versionControl.QueryHistory(”$/”, VersionSpec.Latest, 0, RecursionType.Full, null,  fromDateVersion, toDateVersion, int.MaxValue,true, true);

You can use versionControl Object to get many information from TFS.

Enhanced by Zemanta

Leave a Reply

Your email address will not be published. Required fields are marked *