GetLocalWorkspaceInfo总是得到null

本文关键字:null GetLocalWorkspaceInfo | 更新日期: 2023-09-27 18:18:33

我的问题非常类似于TFS API: GetLocalWorkspaceInfo总是返回null,除了我使用visual studio 2015,所以这些答案并不真正适合我。我试过GetAllLocalWorkspaceInfo,它也返回null。

谢谢

GetLocalWorkspaceInfo总是得到null

我已经测试了你在VS 2015中提到的代码片段,并获得了成功的结果。确保你已经在VS 2015中引用了dll: c:'program files (x86)'Microsoft Visual Studio 14.0'Common7'IDE'CommonExtensions'Microsoft'TeamFoundation'T‌​eam Explorer

在代码片段中,您需要使用Console.WriteLine来输出您想要的工作空间信息:

private static Workspace FindWorkspaceByPath(TfsTeamProjectCollection tfs, string workspacePath)
        {
            VersionControlServer versionControl = tfs.GetService<VersionControlServer>();
            WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(workspacePath);
            if (workspaceInfo != null)
            {
                Console.WriteLine(workspaceInfo.Computer);
                Console.WriteLine(workspaceInfo.DisplayName);
                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));
        }

我发现这个问题是由于软件包版本,所以如果你有这个问题,请检查你的软件包版本是否与你的visual studio版本匹配