Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Source Control Architecture 

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

VersionControlServer

Represents the Team Foundation Server server.

Workspace

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft