TFS API:GetLocalWorkspaceInfo始终返回null [英] TFS API: GetLocalWorkspaceInfo always returns null
问题描述
在我的机器之一,我得到任何 GetLocalWorkspaceInfo
调用返回null值。我已经隔离问题的地方,甚至失败为这个简单的程序:
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 program:
namespace WorkstationTest
{
using Microsoft.TeamFoundation.VersionControl.Client;
class Program
{
static void Main()
{
string workspaceLocalPath = @"C:\Dev";
var info = Workstation.Current
.GetLocalWorkspaceInfo(workspaceLocalPath);
// info is always null here
}
}
}
我已经检查:
-
完全相同的代码工作我的其他机器上的这样它应该
The exact same code works on my other machine the way it should.
我已经验证了我在工作区C:\Dev
我创建了一个新的工作区,并在不同的目录,并在代码以匹配改变了 workspaceLocalPath
变量。
I have created a new workspace and in a different directory and changed the workspaceLocalPath
variable in the code to match.
我已经咨询,其中列明了文档返回值将是空如果路径是不是在工作区
。从上面的图片中,路径应在一个工作区。
I have consulted the documentation which states that the return value will be null if the path is not in a workspace
. From the above image, the path should be in a workspace.
然而,一切似乎在暗示这应该工作。有什么我可能会错过?
Yet, everything seems to suggest this should work. Is there anything I could be missing?
推荐答案
我知道这是一个古老的职位,但就跟大家分享的解决办法,我们有,通过使用VersionControlServer.QueryWorkspaces来查询他/她的机器上的用户的所有工作区。
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<VersionControlServer>();
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));
}
这篇关于TFS API:GetLocalWorkspaceInfo始终返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!