See topic. Everything works fine on my devmachine where VStudio2010 are installed. But not on a clean test server (The setup project includes all used TFS assemblies).
The docs http://msdn.microsoft.com/en-us/library/ff735997.aspx is not very helpful about the return value:
Null if no match is found.
Should I use another method to get a TFS connection? I'm just trying to list and download some files from a specific project.
Update
I reverted back to this:
var uri = new Uri("http://myserver/");
var tfs = new TeamFoundationServer(uri);
var versionControl = tfs.GetService<VersionControlServer>();
Which works. But TeamFoundationServer is obsolete. So I would like to know how to do it in the new way.
I use:
var uri = new Uri("http://myserver/");
var server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(uri);
I had the same issue. The RegisteredTfsConnections.GetProjectCollection() method was not consistently returning collections. This wasn't by user but strangely by computer. My dev box showed all collections and my test box showed none.
In my research I found an MSDN article/solution which may help anyone whom currently wants to get a list of TFS collections on the server.
"Sample Code: Connect to Team Foundation Server" by Allen Clark
It worked for me in Team Foundation Server Object Model v12.
I ran into the same issue today. The reason why I was getting a null return was that some users were using TFS through the web interface and they had not added the server through the Visual Studio plugin for TFS.
The answer from RegisteredTfsConnections.GetProjectCollection I get null exception also worked for this situation.
var tfs = new TfsTeamProjectCollection(new Uri("http://example.com:8080/tfs/DefaultCollection"));
var versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
来源:https://stackoverflow.com/questions/4791031/registeredtfsconnections-getprojectcollection-returns-null-on-test-server-but-n