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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With