TFS API - 如何确保Workspace.OwnerIdentifier不为null?

时间:2017-09-11 19:40:36

标签: tfs tfs-sdk

我有以下代码

var ws = vcs.GetWorkspace(wsName, vcs.AuthorizedUser);

但是,ws.OwnerIdentifier此时为空。我接下来要做的是:

ws.Update(new UpdateWorkspaceParameters { Computer = ws.Computer });

然后ws.OwnerIdentifier不再为空。

在我的场景中必须有更好的方法来获取ws.OwnerIdentifier。有什么想法吗?

我们的后端是2017年TFS。

1 个答案:

答案 0 :(得分:0)

我可以在安装了NuGet包Microsoft.TeamFoundationServer.ExtendedClient的情况下正确获取ws.OwnerIdentifier值。尝试使用版本15.xxx和14.xx,两者都有效。

您需要使用引号指定wsName :( See VersionControlServer.GetWorkspace Method (String, String)

var ws = vcs.GetWorkspace("wsName", vcs.AuthorizedUser);

以下示例供您参考:

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

namespace _0912_GetWorkSpaceIdentifier
{
    class Program
    {
        static void Main(string[] args)
        {
            string collection = @"http://server:8080/tfs/DefaultCollection";
            var tfsServer = new Uri(collection);
            var tpc = new TfsTeamProjectCollection(tfsServer);
            var vcs = tpc.GetService<VersionControlServer>();
            var ws = vcs.GetWorkspace("LC0706-2", vcs.AuthorizedUser);
            var idf = ws.OwnerIdentifier;

            Console.WriteLine(idf);
        }
    }
}

enter image description here