我正在使用此代码从Visual Studio Online存储库下载最新版本:
NetworkCredential netCred = new NetworkCredential(userName, password);
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(serverURL), tfsCred);
tpc.Authenticate();
var versionControl = tpc.GetService<VersionControlServer>();
versionControl.NonFatalError += versionControl_NonFatalError;
var files = versionControl.GetItems(vSOLproject, VersionSpec.Latest, RecursionType.Full);
foreach (Item item in files.Items)
{
var localFilePath = GetLocalFilePath(item, vSOLproject, folderDestination);
switch (item.ItemType)
{
case ItemType.File:
item.DownloadFile(localFilePath);
break;
case ItemType.Folder:
Directory.CreateDirectory(localFilePath);
break;
}
}
这很好用。但是,如何删除与源代码管理的连接,以便我可以编辑文件而不检查它们?
答案 0 :(得分:0)
您需要映射本地工作区并完成该工作区。这是一个简单的示例,它将团队项目集合中的所有团队项目映射到本地工作区,然后下载文件:
var tpc = new TfsTeamProjectCollection(new Uri("http://localhost:8080/tfs/DefaultCollection"));
var vcs = tpc.GetService<VersionControlServer>();
var result = vcs.TryGetWorkspace(@"C:\MySourceCode") ??
vcs.CreateWorkspace(new CreateWorkspaceParameters("MyWorkSpace")
{
Location = WorkspaceLocation.Local,
Folders = new []
{
new WorkingFolder("$/", @"C:\MySourceCode", WorkingFolderType.Map, RecursionType.Full)
}
});
result.Get(VersionSpec.Latest, GetOptions.GetAll);
但是,在IDE中工作可能更有意义。 TFS最强大的一点是它与Visual Studio的集成。