Visual Studio Online-下载代码,然后断开连接

本文关键字:然后 断开 连接 代码 Studio Online- 下载 Visual | 更新日期: 2023-09-27 18:00:51

我正在使用此代码从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;
                }
}

这很好用。但是,我如何删除与源代码管理的连接,以便在不签出文件的情况下编辑文件?

Visual Studio Online-下载代码,然后断开连接

您需要映射一个本地工作区并解决这个问题。下面是一个简单的例子,它将团队项目集合中的所有团队项目映射到本地工作区,然后下载文件:

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的集成。