How do you connect to a TFS server in C# using specific credentials?

前端 未结 3 1228
轻奢々
轻奢々 2021-01-05 01:38

I am attempting to write a c# application that connects to TFS and retrieves work item information. Unfortunately, it seems like all examples of using the TFS SDK are using

3条回答
  •  借酒劲吻你
    2021-01-05 01:51

    Years down the line, this is how you do it with TFS 2013 API:

    // Connect to TFS Work Item Store
    ICredentials networkCredential = new NetworkCredential(tfsUsername, tfsPassword, domain);
    Uri tfsUri = new Uri(@"http://my-server:8080/tfs/DefaultCollection");
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(tfsUri, networkCredential);
    WorkItemStore witStore = new WorkItemStore(tfs);
    

    If that doesn't work, try to pass the credentials through other Credential classes (worked for me):

    // Translate username and password to TFS Credentials
    ICredentials networkCredential = new NetworkCredential(tfsUsername, tfsPassword, domain);
    WindowsCredential windowsCredential = new WindowsCredential(networkCredential);
    TfsClientCredentials tfsCredential = new TfsClientCredentials(windowsCredential, false);
    
    // Connect to TFS Work Item Store
    Uri tfsUri = new Uri(@"http://my-server:8080/tfs/DefaultCollection");
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(tfsUri, tfsCredential);
    WorkItemStore witStore = new WorkItemStore(tfs);
    

提交回复
热议问题