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

前端 未结 6 2042
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 19:43

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

6条回答
  •  無奈伤痛
    2020-12-23 20:33

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

提交回复
热议问题