我倒是希望更新施加到分支编程的标签。在寻找可以做到这一点的方法时,我找到了VersionControlServer.CreateLabel() - Method。 https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.createlabel(v=vs.120).aspx如何通过使用VersionControlServer.CreateLabel()[C#]来更新TFS标签[TFS]
我试了一下这样的,但它似乎doesn't工作:
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsuri));
var vcs = tfs.GetService<VersionControlServer>();
string labelscope = "$/MyProjects/" + machinenumber;
var specifiedBranch = vcs.QueryLabels(label, labelscope, null, true);
string branch = specifiedBranch[0].Items[0].ServerItem;
ItemSpec newItemSpec = new ItemSpec(branch, RecursionType.Full);
string newItem = specifiedBranch[0].Items[0].ServerItem;
newItemSpec.Item = newItem;
VersionSpec versSpec = new LabelVersionSpec(label);
LabelItemSpec newLabelItemSpec = new LabelItemSpec(newItemSpec, versSpec, false);
LabelItemSpec[] newLabelItemSpecList = new LabelItemSpec[1] { newLabelItemSpec };
string labelOwner = vcs.AuthenticatedUser;
string labelName = label.Insert(6, "ed");
VersionControlLabel labelToUpdate = new VersionControlLabel(vcs, labelName, labelOwner, branch, null);
vcs.CreateLabel(labelToUpdate, newLabelItemSpecList, LabelChildOption.Replace);
我究竟想要做的是从“部署”到“部署”更新旧标签名称。我知道如何使用TF.exe执行此操作,但它应该在没有TF.exe的情况下运行。
有没有人有代码示例如何使用CreateLabel() - Methode更新现有标签?
- 更新 -
我改变
LabelItemSpec newLabelItemSpec = new LabelItemSpec(newItemSpec, versSpec, true);
到
现在针对同一分支建立的新标签。我不能用VersionControlServer.DeleteLabel删除旧标签。然后我得到我正在寻找的结果,但我仍然想知道如何正确更新。
谢谢您的回复。我之前和之前曾经写过这篇文章,我发现了一种通过删除旧标签并设置新标签来解决问题的方法。所以对我来说没问题。但是“创建或更新”是什么意思?正如在描述行中所写:https://msdn.microsoft.com/en-us/library/bb138611(v=vs.120).aspx。我会认为“更新”意味着我可以更新标签名称。 – L4c0573
已更新我的回答供您参考。 –
好的非常感谢你!现在对我来说很清楚。 – L4c0573