References:
- http://blogs.msdn.com/b/buckh/archive/2012/03/10/team-foundation-version-control-client-api-example-for-tfs-2010-and-newer.aspx
- http://msdn.microsoft.com/en-us/magazine/jj553516.aspx
- http://msdn.microsoft.com/en-us/magazine/jj883959.aspx
Common Tasks:
Download all files under a directory:
var tfsLocation = "http://<location of TFS>";
var tfsFolder = "$/Xyz";
using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(tfsLocation)))
{
// Get a reference to Version Control.
VersionControlServer versionControl = tpc.GetService<VersionControlServer>();
var path = Path.Combine(tfsFolder, "*.dll");
foreach (var item in versionControl.GetItems(path).Items)
{
list.Add(Assembly.Load(ReadFully(item.DownloadFile())));
}
}
Check if a file exists in TFS:
using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
new Uri("http://tfs:8080/tfs/DefaultCollection")))
{
var server = tfs.GetService<VersionControlServer>();
Boolean doesFileExist = server.ServerItemExists("$/Project/Main/MySoltuion.sln", ItemType.File);
}
Enumerate all the workspaces:
var workspaces = versionControl.QueryWorkspaces(null, versionControl.AuthorizedUser, Environment.MachineName);