Get TFS mapped folder of a local sub folder of the solution?

泄露秘密 提交于 2019-12-12 20:22:28

问题


Let's say we have a solution in TFS Source Control which has already been mapped to a local folder SolutionFolder.

We are in a sub folder SubFolder of this SolutionFolder. How can we write C# code to get the mapped path of this SubFolder?


回答1:


Use the WorkStation.Current to grab the information for the folder in question:

Import the following namespaces:

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

and then use you can get to the data you want through:

var workspace = Workstation.Current.GetLocalWorkspaceInfo(solutionFolder);
if (workspace != null)
{
    var teamProjectUri = workspace.ServerUri;

    // var server = TfsConfigurationServerFactory.GetConfigurationServer(teamProjectUri);
    var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(teamProjectUri);   
    var cssService = projectCollection.GetService<ICommonStructureService4>();
    var project = cssService.GetProjectFromName(solutionName);
}

From there you can easily grab the Workspace as well and from there the serverpath: workspace.GetWorkspace().GetServerItemForLocalItem()

To provide credentials, you can use one of the additional overloads that accepts a CredentialsProvider. The default provider is the UICredentialsProvider. Or you can also call server or projectCollection's EnsureAuthenticated.

See also:

  • https://jessehouwing.net/vsts-tfs-api-auto-detect-connection-details/


来源:https://stackoverflow.com/questions/20565397/get-tfs-mapped-folder-of-a-local-sub-folder-of-the-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!