如何以编程方式签出项目以在 TFS 中进行编辑? [英] How can I programmatically check-out an item for edit in TFS?

查看:23
本文介绍了如何以编程方式签出项目以在 TFS 中进行编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 TFS 2010 处理受源代码控制的实用程序处理文件.

I'm working on a utility processing files being under source control using TFS 2010.

如果一个项目尚未签出进行编辑,我会收到一个异常,这是绝对可以预测的,因为文件处于只读模式.

If an item is not yet checked-out for edit, I'm getting an exception, what is definitely predictable because file is in read-only mode.

检出文件的方法有哪些?

What ways exist to check-out a file?

附言我想要一些编程而不是 Process.Start("tf.exe", "..."); 如果适用.

P.S. I want something for programmatic rather then Process.Start("tf.exe", "..."); if that's applicable.

推荐答案

这里提到的一些其他方法仅适用于特定版本的 TFS 或使用过时的方法.如果您收到 404,则您使用的方法可能与您的服务器版本不兼容.

Some of the other approaches mentioned here only work for certain versions of TFS or make use of obsolete methods. If you are receiving a 404, the approach you are using is probably not compatible with your server version.

这种方法适用于 2005、2008 和 2010.我不再使用 TFS,所以我没有测试 2013.

This approach works on 2005, 2008, and 2010. I don't use TFS any longer, so I haven't tested 2013.

var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
using (var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri))
{
    var workspace = workspaceInfo.GetWorkspace(server);    
    workspace.PendEdit(fileName);
}

这篇关于如何以编程方式签出项目以在 TFS 中进行编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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