简体   繁体   English

以编程方式重命名 TFS 分支 c# (TFS2017)

[英]Rename TFS Branch Programaticly c# (TFS2017)

I'm trying to rename a branch programaticly using "PendRename" method from Microsoft.TeamFoundation.VersionControl.Client.我正在尝试使用 Microsoft.TeamFoundation.VersionControl.Client 中的“PendRename”方法以编程方式重命名分支。

Moves working, so, if I use this to move everything to a new location, it works, but what I need is to rename a branch.移动工作,因此,如果我使用它来将所有内容移动到新位置,它可以工作,但我需要的是重命名一个分支。 It is possible to do this by commandline "tfs.exe rename " (even this is given me errors if I have more than one workspace mapped for the same server url. the ... could not be found in your workspace, or you do not have permission to access it.)可以通过命令行“tfs.exe rename”来做到这一点(如果我为同一个服务器 url 映射了多个工作区,即使这也会给我错误。在你的工作区中找不到 ...没有权限访问它。)

So, could you please help to understand why rename a branch is not working?那么,您能否帮助理解为什么重命名分支不起作用?

Thank you,谢谢,

To Rename or move files and folders in TFVC , you must be one of the Contributors for your team project.在 TFVC 中重命名或移动文件和文件夹,您必须是团队项目的贡献者之一。 See Team Foundation Server default groups, permissions, and roles .请参阅Team Foundation Server 默认组、权限和角色

I tested that and renamed the branch correctly with the " PendRename " method.我对此进行了测试并使用“ PendRename ”方法正确重命名了分支。

Below code sample for your reference:以下代码示例供您参考:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace RenameBranch
{
    class Program
    {
        static void Main(string[] args)
        {
            string oldPath = @"E:\andy\0418Scrum\web0418-0823";
            string newPath = @"E:\andy\0418Scrum\web0418-1020";
            string collection = @"http://server:8080/tfs/DefaultCollection";
            var tfsServer = new Uri(collection);
            var tpc = new TfsTeamProjectCollection(tfsServer);
            var vcs = tpc.GetService<VersionControlServer>();

            Workspace workspace = vcs.GetWorkspace("YourWorkspaceName", vcs.AuthorizedUser);

            workspace.PendRename(oldPath, newPath);
        }
    }
}

Then you need CheckIn it of course.那你当然需要 CheckIn 了。 Use a "workspace.GetPendingChanges()" and "workspace.CheckIn()" methods to do it.使用“workspace.GetPendingChanges()”和“workspace.CheckIn()”方法来做到这一点。

在此处输入图片说明

Thank you,谢谢,

The problem was, there are different processes that are generating workspaces to the directory, and then, he can't remove it.问题是,有不同的进程正在为目录生成工作区,然后,他无法删除它。

So, I solve this issue doing this steps: 1. reserve a workspace local location for my app´ 2. see if this workspace is mapped.所以,我通过以下步骤解决了这个问题:1. 为我的应用程序保留一个工作区本地位置 2. 查看是否映射了此工作区。 If yes, I remove it 3. create a workspace to the previous folder in path and create the map 4. get latest 5. rename如果是,我将其删除 3. 在路径中的前一个文件夹中创建一个工作区并创建地图 4. 获取最新的 5. 重命名

Thank you Andy-MSFT for your support.感谢 Andy-MSFT 的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM