简体   繁体   中英

How to retrieve and set mapping of project on TFS

How can I get mapping of current project on TFS 2010? I need to take single file, find out its mapping and with that information I want to find this file on another computer, which has mapped same workspace. Any idea how can I achieve this?

Your question is a little bit unclear.

Whats your main goal?

If you install Team Foundation Sidekicks you can have a view called "Workspace Sidekick".

There you can filter by computername, Owner (User) and access date (first/last).

With TFS Sidekicks its a little bit easier to find mapped workspaces.

Workspace Sidekick

So I've found solution by myself. First I get server name for every file

try
{
WorkspaceInfo wsi = Workstation.Current.GetLocalWorkspaceInfo(localFileName);
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(wsi.ServerUri);
Workspace wr = wsi.GetWorkspace(tfs);
string ret = wr.TryGetServerItemForLocalItem(localFileName);
return ret;
}
catch
{
  return null;
} 

and than, on another computer, I can load local names

try
{
Uri serverUri = new Uri(uri);
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(serverUri);
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));   
Workstation.Current.EnsureUpdateWorkspaceInfoCache(vcs, Environment.UserName);
Workspace wr = vcs.GetWorkspace(Environment.MachineName, Environment.UserName);
string ret=wr.TryGetLocalItemForServerItem(serverFileName);
return ret;
}
catch
{
  return null;
}

It has some limitations, but works perfect for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM