2017-09-29 1 views
2

현재 GetWorkspace을 호출하면 ItemNotMappedException 예외가 발생하지만 수동으로 작업 영역을 반복 할 때 코드가 작동 할 수 있습니다. 이것은 이상한 일로 GetWorkspace으로 전화하기 전에 새로 고침이나 다른 것을해야하는지 궁금합니다.TFS에서 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의의 repo에서 가져온 것입니다. "Microsoft.TeamFoundationServer.ExtendedClient"버전 "15.112.1"입니다.

+1

이 다음의 중복 :

TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("<your-tfs-uri-here>")); VersionControlServer tfServer = tpc.GetService<VersionControlServer>(); Workstation.Current.EnsureUpdateWorkspaceInfoCache(tfServer, tfServer.AuthorizedUser); 

이 비슷한 질문을 살펴 유무 :

작업 공간 정보 캐시를 업데이트 강제로 코드에서 Workstation.EnsureUpdateWorkspaceInfoCache에 전화를 시도? https://stackoverflow.com/questions/29976960/issue-with-tfs-versioncontrolserver-getworkspace-throwing-itemnotmappedexception –

+1

@BernardVanderBeken을 참조하십시오. 고맙습니다.하지만, 잠시 후에 내 질문을 업데이트하겠습니다. – astrowalker

답변

1

VersionControlServer.GetWorkspace 메서드는 현재 컴퓨터의 알려진 작업 영역을 모두 검색하여 명시 적 또는 묵시적으로 이 제공된 로컬 경로에 매핑 된 작업 영역을 식별합니다. 작업 영역이 없으면이 메서드는 ItemNotMappedException을 반환합니다. Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException even when the workspace exists and has a mapping

+0

고맙습니다.이게 내 문제를 해결했습니다! – astrowalker