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

前端 未结 6 2053
隐瞒了意图╮
隐瞒了意图╮ 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:29

    private const string tfsServer = @"http://tfsserver.org:8080/tfs";
    
    public void CheckOutFromTFS(string fileName)
    {
        using (TfsTeamProjectCollection pc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServer)))        
        {
            if (pc != null)
            {
                WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
                if (null != workspaceInfo)
                {                   
                    Workspace workspace = workspaceInfo.GetWorkspace(pc);
                    workspace.PendEdit(fileName);
                }
            }
        }
        FileInfo fi = new FileInfo(fileName);
    }
    

    Note that Microsoft.TeamFoundation.Client.TeamFoundationServerFactory is obsolete: The TeamFoundationServer class is obsolete. Use the TeamFoundationProjectCollection or TfsConfigurationServer classes to talk to a 2010 Team Foundation Server. In order to talk to a 2005 or 2008 Team Foundation Server use the TeamFoundationProjectCollection class. The corresponding factory class for that is the TfsTeamProjectCollectionFactory.

提交回复
热议问题