问题描述
当前,当我调用 GetWorkspace
时,出现 ItemNotMappedException
异常,但是当我手动遍历工作区时,我可以使代码正常工作.这太奇怪了,我想知道在调用 GetWorkspace
之前是否应该进行刷新或其他操作?
Currently when I call GetWorkspace
I get ItemNotMappedException
exception, but when I iterate over workspaces manually I can get my code working. This is so bizarre that I am wondering if I should call some refresh or something before I call GetWorkspace
?
这是我的代码:
Workspace active = null;
using (var tfs = new TfsTeamProjectCollection(uri))
{
tfs.EnsureAuthenticated();
VersionControlServer vcs = tfs.GetService<VersionControlServer>();
// displaying info and manually finding desired workspace
foreach (var ws in vcs.QueryWorkspaces(null, vcs.AuthorizedUser, Environment.MachineName))
{
Console.WriteLine(ws.Name);
foreach (var f in ws.Folders)
{
Console.WriteLine($" {f.LocalItem}");
if (f.LocalItem == map_path)
active = ws;
}
}
// at this point workspace is found and I can work with it
// but this will crash
Workspace workspace = vcs.GetWorkspace(map_path);
}
我使用VS2015,TFS库是从NuGet存储库中获取的.它是"Microsoft.TeamFoundationServer.ExtendedClient"版本"15.112.1".
I use VS2015 and the library for TFS is fetched from NuGet repo. It is "Microsoft.TeamFoundationServer.ExtendedClient" version "15.112.1".
推荐答案
VersionControlServer.GetWorkspace
方法搜索当前计算机上的所有已知工作区,以标识具有明确或隐式映射的工作区提供的本地路径.如果找不到工作空间,则此方法将引发 ItemNotMappedException .
The VersionControlServer.GetWorkspace
method searches all known workspaces on the current computer to identify a workspace that has explicitly or implicitly mapped the provided local path. If no workspace is found, this method throws an ItemNotMappedException.
尝试调用 Workstation.EnsureUpdateWorkspaceInfoCache
在您的代码中强制更新工作区信息缓存:
Try to call to Workstation.EnsureUpdateWorkspaceInfoCache
in your code to force update the workspace information cache:
TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("<your-tfs-uri-here>"));
VersionControlServer tfServer = tpc.GetService<VersionControlServer>();
Workstation.Current.EnsureUpdateWorkspaceInfoCache(tfServer, tfServer.AuthorizedUser);
看看这个类似的问题: Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException,即使工作空间存在并且具有映射
Have a look at this similar question: Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException even when the workspace exists and has a mapping
这篇关于如何在TFS中正确调用GetWorkspace?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!