加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

来自C#的TFS /文件签出

发布时间:2020-12-15 08:28:38 所属栏目:百科 来源:网络整理
导读:除了将它用于源代码控制之外,我对TFS没有太多经验.我正在开发一个C#应用程序,它需要修改由TFS控制的文件.从我的C#应用??程序中,如何查看通过TFS控制的文件? 谢谢 – 兰迪 解决方法 您可以使用PendEdit使文件可写,对其进行更改,然后将其添加到挂起的更改中,
除了将它用于源代码控制之外,我对TFS没有太多经验.我正在开发一个C#应用程序,它需要修改由TFS控制的文件.从我的C#应用??程序中,如何查看通过TFS控制的文件?

谢谢 – 兰迪

解决方法

您可以使用PendEdit使文件可写,对其进行更改,然后将其添加到挂起的更改中,最后将其签入.

下面是一些代码,其中创建文件夹结构然后签入(非常类似于您将需要的).

private static void CreateNodes(ItemCollection nodes)
{
    using (var tfs = TeamFoundationServerFactory.GetServer("http://tfsserver:8080"))
    {
        var versionControlServer = tfs.GetService(typeof (VersionControlServer)) as VersionControlServer;
        versionControlServer.NonFatalError += OnNonFatalError;

        // Create a new workspace for the currently authenticated user.             
        var workspace = versionControlServer.CreateWorkspace("Temporary Workspace",versionControlServer.AuthenticatedUser);

        try
        {
            // Check if a mapping already exists.
            var workingFolder = new WorkingFolder("$/testagile",@"c:tempFolder");

            // Create the mapping (if it exists already,it just overides it,that is fine).
            workspace.CreateMapping(workingFolder);

            // Go through the folder structure defined and create it locally,then check in the changes.
            CreateFolderStructure(workspace,nodes,workingFolder.LocalItem);

            // Check in the changes made.
            workspace.CheckIn(workspace.GetPendingChanges(),"This is my comment");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            // Cleanup the workspace.
            workspace.Delete();

            // Remove the temp folder used.
            Directory.Delete("tempFolder",true);
        }
    }
}

private static void CreateFolderStructure(Workspace workspace,ItemCollection nodes,string initialPath)
{
    foreach (RadTreeViewItem node in nodes)
    {
        var newFolderPath = initialPath + @"" + node.Header;
        Directory.CreateDirectory(newFolderPath);
        workspace.PendAdd(newFolderPath);
        if (node.HasItems)
        {
            CreateFolderStructure(workspace,node.Items,newFolderPath);
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读