Posts mit dem Label TFS API werden angezeigt. Alle Posts anzeigen
Posts mit dem Label TFS API werden angezeigt. Alle Posts anzeigen

Dienstag, 3. Dezember 2013

Get all changesets contained in a merge operation

When merging changes from one TFS branch to another, you can select to merge all changes up to a specific Version, or you can perform a chery pick merge. The latter means, that you pick the changesets you want to merge manually, which allows you to pick a not coherent sequence of changesets for merge.

If you want to know, given a changeset number representing a changeset that contains merges, changes from which changesets are included, afaik you need to aks the TFS API. To make life easier for you, here is my solution:


var tfs = new TfsTeamProjectCollection(new Uri("http://yourServer:8080/tfs/DefaultCollection"));
tfs.EnsureAuthenticated();
var versionControl = tfs.GetService<VersionControlServer>();

var changeSet = versionControl.GetChangeset(3894);
var mergeParentChangesets = changeSet.Changes
                                        .SelectMany(c => versionControl.QueryMergeRelationships(c.Item.ServerItem))
                                        .Select(i => i.Version)
                                        .Cast<ChangesetVersionSpec>()
                                        .Select(i => i.ChangesetId)
                                        .Distinct();


Here my changeset number is 3894. I iterate over all the changes in the changeset, asking for the merge relationships of each Change. I have to use SelectMany as QueryMergeRelationships returns an array of VersionSpec instances. Indeed, all these instances are truely ChangesetsVersionSpec objects, hence the cast. The latter object exposes the changeset id that we can collect in a distinct list.

Hope this helps, and happy merging!

Dienstag, 1. Oktober 2013

BASTA 2013 Follow Up

Auf der diesjährigen BASTA durfte ich unter dem Titel "Talk to my TFS" zum Thema TFS-API sprechen.

Folien und Demos zum Vortrag stehen jetzt zum download bereit.

Fragen und Kommentare zum Vortrag nehme ich gerne entgegen!

Viel Spaß mit dem Demos und dem TFS!

Sonntag, 16. September 2012

Creating a child task for a backlog item with TFS API

Because TFS Express lacks the agile planning tools of the full version, I was writing a small tool that makes creating tasks as children of a backlog item more enjoyable. It took me a while to figure it out, so I share my result.

First you need a reference to the team project collection:

var tfs = new TfsTeamProjectCollection(new Uri("https://your.tfspreview.com"));
tfs.EnsureAuthenticated();

var workItemStore = tfs.GetService<WorkItemStore>();

The the new task work item must be created. To instanciate a work item you must pass its type. You get this from the Project class.

var project = workItemStore.Projects["NameOfYourTeamProject"];
var taskType = project.WorkItemTypes["Task"];
var task = new WorkItem(taskType);
task.Title = "A new task"; 
task.State = "To Do";      
task.Save();

Next, we need to create a parent / child link. We need a WorkItemLinkTypeEnd instance that we can get from the WorkItemLinkType that we can get from the work item store like this:

var linkType = workItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"];
var taskLink = new WorkItemLink(linkType.ReverseEnd, task.Id);

The taskLink instance is a parent / child work item link whose reverse end (where it points to aka the child) points to the id of the task work item we created formerly. To connect the close end to the parent, the backlog item, we have to load it and put the link into its Links collection:

var backlogItem = workItemStore.GetWorkItem(backlogItemId);´
backlogItem.Links.Add(taskLink);
backlogItem.Save();

Thats it - the new task appears as a child of the backlog item (for example in the taskboard). Hope this may save someone some time :-)