获取解决方案的本地子文件夹的TFS映射文件夹? [英] Get TFS mapped folder of a local sub folder of the solution?

查看:118
本文介绍了获取解决方案的本地子文件夹的TFS映射文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们在TFS Source Control中有一个解决方案,该解决方案已经映射到本地文件夹SolutionFolder.

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

我们在此SolutionFolder的子文件夹SubFolder中. 我们如何编写C#代码以获取此SubFolder的映射路径?

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

推荐答案

使用WorkStation.Current获取有关文件夹的信息:

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

导入以下名称空间:

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);
}

您还可以从那里轻松地获取Workspace,并从那里轻松获取服务器路径:

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

要提供凭据,可以使用接受CredentialsProvider的其他重载之一.默认提供程序为 UICredentialsProvider .或者,您也可以在projectCollection

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.

另请参阅:

这篇关于获取解决方案的本地子文件夹的TFS映射文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆