我的問題是非常相似TFS API: GetLocalWorkspaceInfo always returns null,除了我使用visual studio 2015,所以這些答案真的不適合我。我試過GetAllLocalWorkspaceInfo,它也返回null。GetLocalWorkspaceInfo總是得到空
感謝
我的問題是非常相似TFS API: GetLocalWorkspaceInfo always returns null,除了我使用visual studio 2015,所以這些答案真的不適合我。我試過GetAllLocalWorkspaceInfo,它也返回null。GetLocalWorkspaceInfo總是得到空
感謝
我已經測試的代碼段,你在2015年VS稱並取得成功的結果。請確保您有參考在VS 2015的DLL:c:\program files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team 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));
}
我發現這個問題是因爲的包版本,所以如果你有這個問題,請檢查你的包的版本是否與你的視覺工作室版本相匹配