Wednesday, September 21, 2016

Programmatically adding Labels in TFS

            Using C# code we can Label the files in particular changeset. Below is the code snippet for labeling all files in  given changeset.

 private void LabelChangeset(string fileLabel, Changeset changeset)  
     VersionControlLabel vcl = new VersionControlLabel(vcServer, fileLabel, null, cbProjects.SelectedItem.ToString(), "Autogen label.");  
     LabelItemSpec[] itemSpecs = new LabelItemSpec[changeset.Changes.Length];  
     string ver = string.Format("C{0}", changeset.ChangesetId);  
     VersionSpec fileVersion = VersionSpec.ParseSingleSpec(ver, null);  
     int index = 0;  
     foreach (Change c in changeset.Changes)  
       itemSpecs[index++] = new LabelItemSpec(new ItemSpec(c.Item.ServerItem, RecursionType.None), fileVersion, false);  
     LabelResult[] results = vcServer.CreateLabel(vcl, itemSpecs, LabelChildOption.Replace);  
Original post can be found here:

Bookmark and Share


Post a Comment

Tech World

Label Cloud

Must Buy

  © Blogger templates by updated with tips

Back to TOP