Reputation: 1848
Is there a way to apply a label to a TFS 2008 project/directory with C#? I know of the command line program:
tf label SampleLabel $/Project1/Source/* /recursive /server:TFS1
But i want to do this with C# code, and do NOT want to run TF.exe commandline from C#.
Upvotes: 2
Views: 2217
Reputation: 23157
The following code snippet labels all changes in a particular changeset. It should be straightforward to change it to label all files in a particular path. Instead of iterating through the changeset, just do a vcServer.GetItems("$/Project1/path", RecursionType.Full)
and iterate through them.
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);
}
Upvotes: 3