Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

c# - How can I programmatically check-out an item for edit in TFS?

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?

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

question from:https://stackoverflow.com/questions/5097946/how-can-i-programmatically-check-out-an-item-for-edit-in-tfs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...