TFS API: GetLocalWorkspaceInfo always returns null

前端 未结 8 1301
無奈伤痛
無奈伤痛 2020-12-24 06:46

On one of my machines, I get a return value of null from any GetLocalWorkspaceInfo call. I have isolated to problem to where it even fails for this simple progr

8条回答
  •  天命终不由人
    2020-12-24 06:48

    I know this is an old post, but just like to share the workaround that we have, by using VersionControlServer.QueryWorkspaces to query all the workspaces for the user on his/her machine.

    private static Workspace FindWorkspaceByPath(TfsTeamProjectCollection tfs, string workspacePath)
    { 
        VersionControlServer versionControl = tfs.GetService();
    
        WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(workspacePath);
    
        if (workspaceInfo != null)
        {
            return versionControl.GetWorkspace(workspaceInfo);
        }
    
        // No Workspace found using method 1, try to query all workspaces the user has on this machine.
        Workspace[] workspaces = versionControl.QueryWorkspaces(null, Environment.UserName, Environment.MachineName);
        foreach (Workspace w in workspaces)
        {
            foreach (WorkingFolder f in w.Folders)
            {
                if (f.LocalItem.Equals(workspacePath))
                {
                    return w;
                }
            }
        }
    
        throw new Exception(String.Format("TFS Workspace cannot be determined for {0}.", workspacePath));
    }
    

提交回复
热议问题