采用ICredentialsProvider的TfsTeamProjectCollectionFactory.GetTeamProjectCollection的替代方案

gab*_*ldi 9 .net tfs sdk

按照MSDN的方法GetTeamProjectCollection(RegisteredProjectCollection projectCollection, ICredentialsProvider fallbackCredentialsProvider中的TfsTeamProjectCollectionFactory类现在已经过时:

  • "注意:此API现已过时."

  • [ObsoleteAttribute("This method has been deprecated and will be removed in a future release. See GetTeamProjectCollection(RegisteredProjectCollection) instead.", false)]

建议是使用仅占用的重载RegisteredProjectCollection,但是如果我们想要凭证的回退机制,我们应该从现在开始使用什么?

谢谢

Gra*_*day 12

您需要使用新的TfsTeamProjectCollection构造函数以及此TfsClientCredentials构造函数,该构造函数允许交互式提示进行身份验证.

// 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);
Run Code Online (Sandbox Code Playgroud)