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

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

问题描述

我试图拉的最新版本的源代码了TFS的编程方式使用SDK,以及我所不知何故做不工作:

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:\Projects\Test\TestApp";

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.

推荐答案

我最终使用一种不同的方法,似乎工作,主要是趁着<一个HREF =htt​​p://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.item.downloadfile%28VS.80%29.aspx> 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天全站免登陆