如何使用 Team Foundation Server SDK 获取最新版本的源代码? [英] How do you get the latest version of source code using the Team Foundation Server SDK?

查看:24
本文介绍了如何使用 Team Foundation Server SDK 获取最新版本的源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SDK 以编程方式从 TFS 中提取最新版本的源代码,但我所做的以某种方式不起作用:

I'm attempting to pull the latest version of source code out of TFS programmatically using the SDK, and what I've done somehow does not work:

string workspaceName = "MyWorkspace";
string projectPath = "/TestApp";
string workingDirectory = "C:ProjectsTestTestApp";

VersionControlServer sourceControl; // actually instantiated before this method...

Workspace[] workspaces = sourceControl.QueryWorkspaces(workspaceName, sourceControl.AuthenticatedUser, Workstation.Current.Name);
if (workspaces.Length > 0)
{
    sourceControl.DeleteWorkspace(workspaceName, sourceControl.AuthenticatedUser);
}
Workspace workspace = sourceControl.CreateWorkspace(workspaceName, sourceControl.AuthenticatedUser, "Temporary Workspace");
try
{
    workspace.Map(projectPath, workingDirectory);
    GetRequest request = new GetRequest(new ItemSpec(projectPath, RecursionType.Full), VersionSpec.Latest);
    GetStatus status = workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite); // this line doesn't do anything - no failures or errors
}
finally
{
    if (workspace != null)
    {
        workspace.Delete();
    }
}

该方法基本上是创建一个临时工作区,使用 Get() 方法获取此项目的所有项,然后删除工作区.这是正确的方法吗?任何示例都会有所帮助.

The approach is basically creating a temporary workspace, using the Get() method to grab all the items for this project, and then removing the workspace. Is this the correct way to do this? Any examples would be helpful.

推荐答案

我最终使用了一种似乎有效的不同方法,主要是利用了 Item.DownloadFile() 方法:

I ended up using a different approach that seems to work, mainly taking advantage of the Item.DownloadFile() method:

VersionControlServer sourceControl; // actually instantiated...

ItemSet items = sourceControl.GetItems(sourcePath, VersionSpec.Latest, RecursionType.Full);

foreach (Item item in items.Items)
{
    // build relative path
    string relativePath = BuildRelativePath(sourcePath, item.ServerItem);

    switch (item.ItemType)
    {
    case ItemType.Any:
        throw new ArgumentOutOfRangeException("ItemType returned was Any; expected File or Folder.");
    case ItemType.File:
        item.DownloadFile(Path.Combine(targetPath, relativePath));
        break;
    case ItemType.Folder:
        Directory.CreateDirectory(Path.Combine(targetPath, relativePath));
        break;
    }
}

这篇关于如何使用 Team Foundation Server SDK 获取最新版本的源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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