This code farm recently developed a vs extension, some of which are related to file checkout. Our company is using TFS, encountered some peculiar phenomenon, the resolution process is recorded as follows.
One, clearly online connection but offline attribute equals True
Public StaticWorkspace Getworkspace (stringSlndir) { varProjectcollections =NewList<registeredprojectcollection>( (Registeredtfsconnections.getprojectcollections ())); varOnlinecollections = Projectcollections.where (c =!)c.offline). ToList (); //fail if there is no registered collections that is currently on-line if(!Onlinecollections.any ()) { return NULL; } Workspace Workspace=NULL; //find a project collection with at least one team project foreach(varRegisteredprojectcollectioninchonlinecollections) { varProjectCollection =tfsteamprojectcollectionfactory.getteamprojectcollection (registeredprojectcollection); Projectcollection.ensureauthenticated (); varVersionControl = (versioncontrolserver) projectcollection.getservice (typeof(Versioncontrolserver)); varTeamprojects =NewList<teamproject> (Versioncontrol.getallteamprojects (false)); //If there is no team projects in this collection, skip it if(Teamprojects.count <1)Continue; varDIR =NewDirectoryInfo (Slndir); while(Workspace = =NULL) {Workspace=Versioncontrol.trygetworkspace (dir. FullName); if(dir. Parent = =NULL) Break; Dir=dir. Parent; } if(Workspace! =NULL&&Workspace. Hasusepermission) Break; } returnWorkspace; }
The phenomenon is that the above code
var onlinecollections = Projectcollections.where (c =!c.offline). ToList ();
I can't find the one I want. Online TFS Server
The first attempt to delete the cache in the Local AppData (C:\users\*\appdata\local\microsoft\team Foundation) does not work.
Then find the registry
hkey_users\s-1-5-21-2532103873-3336248781-2863026242-1503\software\microsoft\visualstudio\11.0\teamfoundation\ Instances\tfs.yintai.org\collections\platformcollection
Change this node offline to 0
OK.
The cause is unknown and may be related to multiple TFS connections.
Second, the Trygetworkspace method can not find the corresponding workspace
And then you meet
Workspace = Versioncontrol.trygetworkspace (dir. FullName);
Always returns null
Instead, use the Queryworkspaces method to traverse all workspace to resolve
Put this paragraph
var New DirectoryInfo (slndir); while NULL ) { = versioncontrol.trygetworkspace (dir. FullName); if NULL ) break; = dir. Parent; }
Replaced by
Try{workspace[] workspaces= Versioncontrol.queryworkspaces (NULL, Environment.username, Environment.MachineName); foreach(varWsinchworkspaces) { foreach(varFolderinchws. Folders) {if(Slndir.startswith (folder. Localitem)) {workspace=ws; Break; } } if(Workspace! =NULL&&Workspace. Hasusepermission) Break; } } Catch { Continue; }
The pits encountered in TFS extension development