This documentation is archived and is not being maintained.

Source Control Architecture 

The two primary classes in the Version Control object model are as follows:


Represents the Team Foundation Server server.


Represents an individual workspace.

Each Team Explorer maintains a cache file at the user level that tracks the user’s local workspaces, the directories that are mapped into that workspace, and the server associated with that workspace.

Entry points

The version control object model provides two primary methods as entry points:

  1. If you know the server name:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(serverNameOrUrl);
VersionControl vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
  1. If you have a mapped file or directory and want to get the associated workspace:

    In this scenario, you use the WorkspaceInfo object which represents the workspace’s entry in the cache file. It gives you enough information to get the actual Workspace object and, from the Workspace object, the VersionControlServer.

WorkspaceInfo sourceWorkspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(SourceLocalRoot);
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(sourceWorkspaceInfo.ServerUri.AbsoluteUri);
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
Workspace sourceWorkspace = vcs.GetWorkspace(sourceWorkspaceInfo);

After you have either the VersionControlServer or the Workspace, which gives you the associated VersionControlServer through a property of the same name, then you can do whatever version control operation you want to do. Normally, it should be the same kind of workflow as with the command-line or GUI clients.

See Also