my problem is really similar to TFS API: GetLocalWorkspaceInfo always returns null, except I am using visual studio 2015, so those answers don't really work for me. And I tried GetAllLocalWorkspaceInfo, it returns a null as well.
Thanks
my problem is really similar to TFS API: GetLocalWorkspaceInfo always returns null, except I am using visual studio 2015, so those answers don't really work for me. And I tried GetAllLocalWorkspaceInfo, it returns a null as well.
Thanks
I have tested the code snippet you referred in VS 2015 and got a successful result. Make sure you have reference the dlls in VS 2015: c:\program files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer
And in the code snippet, you need to use Console.WriteLine
to output the workspace information that you want:
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));
}
I found out this issue is because of package version, so if you have this issue, please check the version of your package matches the version of your visual studio