Oliver
Oliver

Reputation: 81

How do I get a list of Team Foundation Server Servers available on my PC?

I need to get Team Foundation Server list programmatically with C#.

This is needed for the TfsTeamProjectCollection object.

Upvotes: 2

Views: 3552

Answers (4)

Sir Crispalot
Sir Crispalot

Reputation: 4854

I had a scan through the documentation and couldn't find anything useful. I believe @samy is correct and there is no discovery mechanism.

However if you are running this on a client machine that already has established connections to TFS then there is a history of servers stored in the registry:

Visual Studio 2008 location:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers

Visual Studio 2010:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\TeamFoundation\Instances\

Visual Studio 2012

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\TeamFoundation\Instances\

Visual Studio 2013

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\TeamFoundation\Instances\

Visual Studio 2015

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\TeamFoundation\Instances\

Upvotes: 8

Joey Adams
Joey Adams

Reputation: 43410

To list all workspaces that "tf workspaces" would return (which includes URI and mapped paths):

var allWorkspaceInfos = Workstation.Current.GetAllLocalWorkspaceInfo();

To get the TFS workspace containing a particular directory:

var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(@"C:\Users\joey\tfs");

I found this by decompiling TF.exe. But there is documentation for the Workstation class.

These methods return WorkspaceInfo objects. To perform source control operations, you need to connect to the server and get a Workspace object:

var collection = new TfsTeamProjectCollection(workspaceInfo.ServerUri);
collection.Authenticate();
var server = collection.GetService<VersionControlServer>();
var workspace = server.GetWorkspace(scriptRoot);

Upvotes: 0

Chuen Lee
Chuen Lee

Reputation: 423

For Visual Studio 2012, the location in the registry key is:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\TeamFoundation\Instances\tfs

Upvotes: 0

samy
samy

Reputation: 14972

I think the responsibility of keeping track of the servers is your responsibility. There's no discovery options for the servers as far as i know. So you need the uris

Upvotes: 0

Related Questions