gpt4 book ai didi

c# - 如何使用 VersionControlServer.CreateLabel() [C#][TFS] 更新 TFS labelname

转载 作者:行者123 更新时间:2023-11-30 23:17:58 25 4
gpt4 key购买 nike

我想更新以编程方式应用于分支的标签。在寻找可以解决问题的方法时,我找到了 VersionControlServer.CreateLabel() 方法。 https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.createlabel(v=vs.120).aspx

我这样试过,但它似乎不起作用:

    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);

我真正想做的是将旧标签名称从“Deploy”更新为“Deployed”。我知道如何使用 TF.exe 执行此操作,但它应该在没有 TF.exe 的情况下工作。

有没有人有代码示例如何使用 CreateLabel()-方法更新现有标签?

-- 更新--

我变了

LabelItemSpec newLabelItemSpec = new LabelItemSpec(newItemSpec, versSpec, true);

LabelItemSpec newLabelItemSpec = new LabelItemSpec(newItemSpec, versSpec, false);

现在为同一个分支创建了一个新标签。我无法使用 VersionControlServer.DeleteLabel 删除旧标签。然后我得到了我正在寻找的结果,但我仍然想知道如何正确更新。

最佳答案

TFS 不支持

重命名 标签。您只能根据要删除的旧标签创建新标签。详情请看此链接:Rename Label in Team Foundation Server

您也可以在 VersionControlLabel Class 中验证这一点.

Name Gets the name of this label.

只能获取名称不能设置名称。


更新

对于 LabelChildOption options VersionControlServer::CreateLabel Method ,一共有三个选项:

  • Replace: Any item that you specify in your request that’s already in the label will be replaced by what you have specified. Anything that’s not in the label already will be added to the label, and existing items that aren’t modified by your request will remain as they were.
  • Merge: Leave unmodified items that are in your request but that already exist in the label. Any item in your request that’s not
    already in the label will be added to the label, and existing items
    in the label that aren’t specified in your label will remain
    unchanged.
  • Fail: Labels have the notion of a scope. The Fail option says that the call to create or update the label should fail if there is
    at least one label by the same name that exists at a scope that would be below the scope of the new label.

更新标签仅表示更新itemSpecs 参数,即标签中包含的项目规范。因此它用于更新标签的 ItemSpec – 我们要标记哪些文件、文件夹。

关于c# - 如何使用 VersionControlServer.CreateLabel() [C#][TFS] 更新 TFS labelname,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41137091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com