Programming TFS

References:

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);
This entry was posted in Software. Bookmark the permalink.

Leave a comment