what's the best way, using the TFS API, to add a label to a file?

Posted by jcollum on Stack Overflow See other posts from Stack Overflow or by jcollum
Published on 2010-03-25T22:32:36Z Indexed on 2010/03/25 23:23 UTC
Read the original article Hit count: 457

Filed under:
|

I'd like to add a label to a set of files using the TFS API. My code looks like this:

VersionControlLabel label = new VersionControlLabel(this.vcServer, this.label,
                this.vcServer.AuthenticatedUser, this.labelScopeDirectory, this.labelComment);

            List<LabelItemSpec> labelSpecs = new List<LabelItemSpec>();

            // iterate files and versions 
            foreach (var fileAndVersion in this.filesAndVersions)
            {
                VersionSpec vs = null;
                Item i = null;
                // i have no idea why the itemspec is needed instead of the item and version... 
                ItemSpec iSpec = new ItemSpec("{0}/{1}".FormatString(this.source, fileAndVersion.Key), RecursionType.None);
                GetItemAndVersionSpec(fileAndVersion.Key, fileAndVersion.Value, out vs, out i);
                labelSpecs.Add(new LabelItemSpec(iSpec, vs, false));
            }

            this.vcServer.CreateLabel(label, labelSpecs.ToArray(), LabelChildOption.Merge);

(there are some extension methods in there... this is all largely lifted from this blog post)

The thing that concerns me is things like this in the MSDN docs:

This enumeration supports the .NET Framework infrastructure 
and is not intended to be used directly from your code. 

So MSDN is telling me not to use that enumeration (LabelChildOption), which is afaik the only way to create a label and add it to a file.

Is there a better way? Is this sort of a "grey" area in the TFS API?

© Stack Overflow or respective owner

Related posts about tfs

Related posts about tfs2008