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

时间:2013-01-01 04:34:49

标签: .net sdk tfs

根据MSDNGetTeamProjectCollection(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的重载,但是如果我们想要一个凭证的回退机制,我们应该从现在开始使用什么?

由于

1 个答案:

答案 0 :(得分:12)

您需要使用新的TfsTeamProjectCollection constructor以及此TfsClientCredentials constructor,它允许交互式提示进行身份验证。

// 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);