问题描述
假设我们在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,并从那里轻松获取服务器路径: workspace.GetWorkspace().GetServerItemForLocalItem()
From there you can easily grab the Workspace as well and from there the serverpath: workspace.GetWorkspace().GetServerItemForLocalItem()
要提供凭据,可以使用接受CredentialsProvider
的其他重载之一.默认提供程序为 UICredentialsProvider
.或者,您也可以在或projectCollection
的 EnsureAuthenticated
.
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映射文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!