2014-04-01 49 views
2

我有一个控制台应用程序,需要从源代码管理(TFS)下载一些文件。但是在使用下面的代码时,VersionControlServer服务为空。由于这个原因,我无法下载我需要的文件。无法从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 

回答

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>(); 
+0

没有。这不行! – user3231442

+0

什么部分不起作用?你有没有找到你的URL到tfs DefaultCollection并在第一行设置? – Shiv