.nettfssdktfs-sdk

Alternative to TfsTeamProjectCollectionFactory.GetTeamProjectCollection taking ICredentialsProvider


According to the MSDN the method GetTeamProjectCollection(RegisteredProjectCollection projectCollection, ICredentialsProvider fallbackCredentialsProvider of the TfsTeamProjectCollectionFactory class is now deprecated:

The advice is to use the overload that only takes the RegisteredProjectCollection, but what should we use from now on if we want a fallback mechanism for credentials?

Thanks


Solution

  • You need to use the new TfsTeamProjectCollection constructor along with this TfsClientCredentials constructor which allows interactive prompts for authentication.

    // Use default windows credentials, and if they fail, AllowInteractive=true
    var tfsCreds = new TfsClientCredentials(new WindowsCredential(), true);
    
    TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
        new Uri("http://yourserver:8080/tfs/DefaultCollection"),
        tfsCreds);