使用C#从TFS下载文件

问题描述 投票:-1回答:1

我正在尝试使用C#编程从TFS下载代码文件。为了实现这一点,需要遵循两个步骤,

  1. 通过C#与TFS建立连接
  2. 路由到该文件夹​​以下载所需的文件。

我目前正在进行第1步,为了实现这一目标,我进行了一些研究,并使用了TFS API,并在下面的代码中使用了该语言,

 public static bool AlwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
    {
        return true;
    }
static void Main(string[] args)
    {
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
        ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
        ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate);
        // Translate username and password to TFS Credentials
        ICredentials networkCredential = new NetworkCredential(@"username", @"password", @"domain");
        WindowsCredential windowsCredential = new WindowsCredential(networkCredential);
        TfsClientCredentials tfsCredential = new TfsClientCredentials(windowsCredential, false);

        // Connect to TFS Work Item Store
        Uri tfsUri = new Uri(@"https://url");
        TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(tfsUri, tfsCredential);
        WorkItemStore witStore = new WorkItemStore(tfs);
}

现在,我无法通过此代码连接到TFS,并且每当我尝试通过输入相同的url,密码,域和用户名尝试使用浏览器进行连接时,我都会成功登录,但由于某些奇怪的原因,我无法使用我的代码。当我尝试通过代码登录时,收到以下错误消息,

enter image description here

c# authentication tfs connection tfsbuild
1个回答
0
投票

正如Shayki Abramczyk建议在网址中也使用集合名称。

所以我使用了下面的URL,它解决了我的问题,

https://server-name:443/tfs/Collection-name
© www.soinside.com 2019 - 2024. All rights reserved.