2013-07-19 2 views
5

私は、プロジェクトがローカルにマッピングされているかどうか、コードからは分かりません。私はMicrosoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory.GetTeamProjectCollection()を使ってすべてのTFSプロジェクトを得ることができます。foreachworkItemStore = new WorkItemStore(projects)にして、多くのプロジェクト情報を取得できますが、IsMappedまたはMappingPathのようなものがあります。プログラムでTFSでマッピングされたプロジェクトがどのようにチェックされていますか?

情報Visual Studioの[チームエクスプローラ]の[ソースコントロールエクスプローラ]から簡単にアクセスできますが、C#コードから実行する必要があります。私が試したものです

​​

UPD:ANSWER

MikeRの答えは良いですが、私はそれが1欠陥を持っていることを追加したいです。ルートディレクトリがマップされているにもかかわらず、ローカルコンピュータのこのルートディレクトリからすべてのプロジェクトを実際に取得していない場合、Mikerのソリューションではすべてのプロジェクトが返されます。あなたのコードは、このように行動したくない場合は、ここに私のソリューションです:

TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_tfsServerUri)); 
teamProjectCollection.Authenticate(); 
VersionControlServer versionControl = teamProjectCollection.GetService<VersionControlServer>(); 

string computerName = Environment.MachineName; 
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent(); 
// get yours local workspaces 
Workspace[] workspaces = versionControl.QueryWorkspaces(null, windowsIdentity.Name, computerName); 

foreach (Project pr in workItemStore.Projects) 
    { 
     var mapped = false; 

     foreach (Workspace workspace in workspaces) 
     { 
      var path = workspace.TryGetLocalItemForServerItem("$/" + pr.Name); 
      if (!String.IsNullOrEmpty(path) && Directory.Exists(path)) 
      { 
       mapped = true; 
      } 
     } 
    // do what you want with mapped project 
    } 

答えて

3

は、これは、より一般的なアプローチですが、私はあなたが、コンパイルされていない(あなたのニーズに合わせてカスタマイズするために管理するだけで指しなると思います方向へ):

string project = "TeamProject1"; 
string serverPath = "$/"+project; 
string computername = "myComputer"; // possibly Environment.Computer or something like that 
var tpc= TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_tfsServerUri)); 
tpc.Authenticate(); 
// connect to VersionControl 
VersionControlServer sourceControl = (VersionControlServer)tpc.GetService(typeof(VersionControlServer)); 
// iterate the local workspaces 
foreach (Workspace workspace in sourceControl.QueryWorkspaces(null, null, computername)) 
{ 
    // check mapped folders 
    foreach (WorkingFolder folder in workspace.Folders) 
    { 
    // e.g. $/TeamProject1 contains $/ if the root is mapped to local 
    if (serverPath.Contains(folder.ServerItem) && !folder.IsCloaked) 
    { 
     Console.WriteLine(serverPath + " is mapped under "+ folder.LocalItem); 
     Console.WriteLine("Workspacename: "+workspace.Name); 
    } 
    } 
} 
関連する問題