2016-11-17 45 views

回答

0

我已經測試的代碼段,你在2015年VS稱並取得成功的結果。請確保您有參考在VS 2015的DLL:c:\program files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\T‌​eam 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)); 
     } 
-2

我發現這個問題是因爲的包版本,所以如果你有這個問題,請檢查你的包的版本是否與你的視覺工作室版本相匹配