用你們&一(謝謝),我能夠進行大量的試驗和錯誤後,把這個樣品在一起。它進一步展示瞭如何映射本地路徑。我希望這可以節省一些讀者頭痛。
這個例子放在一起的形式在VS 2015和使用下列程序集引用(即也是棘手的追查)
所有位於C:\ Program Files文件(x86)的\微軟的Visual Studio 14.0 \ Common7 \ IDE \ Extensions \ vl45o2it.tph在我的機器上。
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.Common.dll
Microsoft.TeamFoundation.VersionControl.Client.dll
Microsoft.VisualStudio.TeamFoundation.dll
道歉,如果我的術語是在地方。如果你編輯這些,我不介意。
using System;
using System.Linq;
using System.Windows.Forms;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Client;
using System.Diagnostics;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace Tfs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Uri tfsUri = new Uri("http://server:8080/tfs");
string repositoryName = "yourrepository";
string projectPath = "$/project/path/path/path";
Uri repositoryUri = new Uri(string.Format("{0}/{1}", tfsUri.AbsoluteUri, repositoryName));
TfsConfigurationServer tfscs = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
//get the repository
CatalogNode repository = tfscs.CatalogNode.QueryChildren(new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None)
.FirstOrDefault(a => string.Compare(a.Resource.DisplayName, repositoryName, true) == 0);
//open in the project collection
TfsTeamProjectCollection pc = tfscs.GetTeamProjectCollection(new Guid(repository.Resource.Properties["InstanceId"]));
//tfs project file structure access
VersionControlServer vcs = pc.GetService<VersionControlServer>();
WorkspaceInfo wsi = Workstation.Current.GetAllLocalWorkspaceInfo().FirstOrDefault(a => a.ServerUri == repositoryUri);
//user functionality (checkin, localpaths etc)
Workspace ws = wsi.GetWorkspace(pc);
//get the file structure
ItemSet items = vcs.GetItems(projectPath, RecursionType.Full);
foreach (Item i in items.Items)
{
Debug.WriteLine(string.Format("{0} ({1}) - {2} - {3}", i.ServerItem,
i.ContentLength.ToString(),
i.ItemType.ToString(),
ws.GetLocalItemForServerItem(i.ServerItem)));
}
}
}
}