Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify 'Current' open workspace through TFS API?

Tags:

api

tfs

Is there a way to programatically determine the current workspace of the open sln/proj in visual studio using the TFS API? I've seen how the VersionControlServer can retreive all of the known workspaces, but is there anything I can use to tie that to what the user currently has (or doesn't have) open?

like image 544
JPero Avatar asked Jan 07 '09 21:01

JPero


1 Answers

There is another override to the GetWorkspace method of an instantiated VersionControlServer object. You can call GetWorkspace with the local path like Bernhard states, but you can also call it with the workspace name and workspace owner. Since the workspace name defaults to the local computer name, you can usually get away with using Environment.MachineName, but there is always going to be that developer who changes the workspace name.

Example:

TeamFoundationServerFactory _tfs = TeamFoundationServerFactory.GetServer(server);
            _tfs.EnsureAuthenticated();

VersionControlServer _vcs = (VersionControlServer)_tfs.GetService(typeof(VersionControlServer));
Workspace _ws = _vcs.GetWorkspace(Environment.MachineName, Environment.UserName);
like image 80
Dave Teply Avatar answered Sep 23 '22 11:09

Dave Teply