【问题标题】:Can't retrieve TFS workspaces in c# with tfs API无法使用 tfs API 在 C# 中检索 TFS 工作区
【发布时间】:2018-07-23 21:00:57
【问题描述】:

我需要获取未映射到我的计算机上的 TFS 工作区的最新版本。

这是我的代码:

using (TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(
    new Uri("http://tfs:8080/tfs/project"), 
    new NetworkCredential("tfs", "pwd")))
{
    tfs.EnsureAuthenticated();

    VersionControlServer vcs = tfs.GetService<VersionControlServer>();

    Workspace w = vcs.GetWorkspace("VM-TFS", vcs.AuthorizedUser);

    // Implement w.Get(.....)
}

问题是在GetWorkspace() 上我收到了一个异常:"TF14061: the workspace VM-TFS;DELTA\\tfs does not exist."(其中用户名之前的'DELTA' 是我们的域。)

我确定用户名是正确的,他是工作区的所有者,工作区的名称也是正确的。

更新

我发现了问题。最初,我使用智能感知直接导入了 .dll。通过这种方式,我认为 Visual Studio 引用了他附带的 dll。 我尝试删除所有这些并使用 NuGet 安装“Microsoft.TeamFoundationServer.ExtendedClient”,现在它可以工作了!

【问题讨论】:

  • 您是否尝试获取所有个工作区的列表并查看返回的结果?
  • 你的意思是API代码?因为我没有找到办法……

标签: c# .net tfs tfs-sdk


【解决方案1】:

我发现了问题。

最初,我使用智能感知直接导入了 .dll。通过这种方式,我认为 Visual Studio 引用了他附带的 dll。我尝试将它们全部删除并使用 NuGet 安装 Microsoft.TeamFoundationServer.ExtendedClient,现在它可以工作了!

【讨论】:

    【解决方案2】:

    我已经用下面的代码进行了测试,得到了成功的结果,你可以试试:

    using Microsoft.TeamFoundation.Client;
    using System;
    using Microsoft.TeamFoundation.VersionControl.Client;
    
    namespace GetLatest
    {
        class Program
        {
            static void Main(string[] args)
            {
                TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://tfsserver:8080/tfs/TeamProjectCollection"));
                var versioncontrols = tfs.GetService<VersionControlServer>();
                var workspace = versioncontrols.GetWorkspace("test", versioncontrols.AuthorizedUser);
                workspace.Get();
    
            }
        }
    }
    

    【讨论】:

    • 看起来和我做的一样...您认为问题可能与工作区的权限有关吗? (为此,我将 NetworkCredenials 给了 TfsTeamProjectCollection 构造函数...)
    • 如果你使用我的代码,你能得到工作空间吗?
    • 抱歉,回答迟了。但是我试过了,我用我自己的 Uri 和工作区名称替换了它,它没有工作......同样的异常......
    • 能否尝试新建一个工作区,看看能否识别?
    猜你喜欢
    • 1970-01-01
    • 2012-09-06
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 2014-11-13
    • 2010-12-06
    • 2011-07-08
    相关资源
    最近更新 更多