//find the working folder for each TFS var projectCollections = RegisteredTfsConnections.GetProjectCollections(); foreach (var registeredProjectCollection in projectCollections) { Console.WriteLine("Project collection: {0} {1}",
registeredProjectCollection.Name,
registeredProjectCollection.Uri.AbsoluteUri); var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(registeredProjectCollection); var versionControl = projectCollection.GetService<VersionControlServer>(); // get workspace var workspace = versionControl.QueryWorkspaces(null, System.Threading.Thread.CurrentPrincipal.Identity.Name, Environment.MachineName) .FirstOrDefault(x => x.Folders.Length > 0 && //if there is a Work Item Manager, we don't care x.Name != "WIM (" + Environment.MachineName + ")"); if(workspace == null) continue; //no workspace for this server //there's normally only one WorkingFolder folder = workspace.Folders.First(); Console.WriteLine("Working folder {0}", folder.LocalItem); }
//old VS 2008 way //using (TeamFoundationServer tfsServer = new TeamFoundationServer(tfsServerName)) //{ // // Get a reference to version control // VersionControlServer versionControl = // (VersionControlServer) tfsServer.GetService(typeof (VersionControlServer)); // //.... //}
Visual Studio 2010 - find TFS working directory
Published Thursday 05 January 2012
Previously: MCPD Web Developer .Net 4 (10 Dec 2011)