无法从TFS获取VersionControlServer服务

时间:2014-04-01 12:41:17

标签: c# visual-studio-2012 version-control tfs

我有一个控制台应用程序,需要从源代码管理(TFS)下载一些文件。但是在使用下面的代码时,VersionControlServer服务为空。因此,我无法下载我需要的文件。

TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(UrlSite));
tpc.EnsureAuthenticated();
bool hasAuthenticated = tpc.HasAuthenticated; // true
var versionControl2 = tpc.GetService<VersionControlServer>(); // null 
var buildServer2 = tpc.GetService<IBuildServer>(); // successful initialization
var workItemStore2 = tpc.GetService<WorkItemStore>(); // successful initialization

1 个答案:

答案 0 :(得分:2)

我做了类似的事情,但稍微不同地实例化TfsTeamProjectCollection,这适用于我们环境中的cmdline应用程序:

string collection = @"http://TFSSERVER:8080/tfs/DefaultCollection";
var tfsServer = new Uri(collection);
var tpc = new TfsTeamProjectCollection(tfsServer);
var versionControl2 = tpc.GetService<VersionControlServer>();
var buildServer2 = tpc.GetService<IBuildServer>();
var workItemStore2 = tpc.GetService<WorkItemStore>();