TFS API - how to make sure Workspace.OwnerIdentifier is not null?

73 Views Asked by At

I have the following code

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

However, ws.OwnerIdentifier is null at this point. What I do next to get the value is:

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

And then ws.OwnerIdentifier is no longer null.

There must be a better way to obtain ws.OwnerIdentifier in my scenario. Any ideas?

Our back-end is TFS 2017.

1

There are 1 best solutions below

2
On

I can get the ws.OwnerIdentifier value correctly with the NuGet package Microsoft.TeamFoundationServer.ExtendedClient installed. Tried with Version 15.xxx and 14.xx, both worked.

You need to specify the wsName with quotes: (See VersionControlServer.GetWorkspace Method (String, String))

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

Below sample for your reference:

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