c# - 如何使用 .Net Windows 服务的新基本身份验证对 Visual Studio Team Services 进行身份验证?

标签 c# .net tfs azure-devops basic-authentication

我正在尝试访问 https://visualstudio.com (以前称为 https://tfs.visualstudio.comhttp://www.tfspreview.com )来 self 在 .NET 上编写的 Windows 服务。

我想使用新的基本身份验证,但找不到实现它的方法。

我找到了很多博客文章的链接 Team Foundation Service updates - Aug 27但它正在为 TFS 使用 Team Explorer Everywhere Java 客户端。

是否有新版本的 TFS .NET 对象模型支持基本身份验证?

顺便说一句,我已经使用服务帐户成功登录了。 This answer非常有用。

最佳答案

首先,你至少需要有Visual Studio 2012 Update 1安装在你的机器上。它包含更新的 Microsoft.TeamFoundation.Client.dll 程序集和 BasicAuthCredential 类。

这是执行此操作的代码,来自 Buck's blog post How to connect to Team Foundation Service .

using System;
using System.Net;
using Microsoft.TeamFoundation.Client;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            NetworkCredential netCred = new NetworkCredential(
                "yourbasicauthusername@live.com",
                "yourbasicauthpassword");
            BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
            TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
            tfsCred.AllowInteractive = false;

            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
                new Uri("https://YourAccountName.visualstudio.com/DefaultCollection"),
                tfsCred);

            tpc.Authenticate();

            Console.WriteLine(tpc.InstanceId);
        }
    }
}

关于c# - 如何使用 .Net Windows 服务的新基本身份验证对 Visual Studio Team Services 进行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13245776/

相关文章:

c# - 在 c# 中使用重定向 (">>"时如何使用 String[] args?

javascript - 如何通过 JavaScript 在 JSON 中构建此 XML 结构?

c# - 将 MVC 操作结果发送到打印机

c# - 使用日期精度运行查询时,您不能提供带日期的时间

c# - 如何使用Visual Studio 2019和C#立即添加所有缺少的用法

c# - 将 WCF 协议(protocol)转换为类

javascript - MVC视频输入时间不变

.net - 加强托管线程和操作系统线程之间的关系(CUDA 用例)

git - 在 libgit2sharp 中使用 TFS PAT 授权

visual-studio-2010 - 如何在 Visual Studio 中轻松识别同一代码库的不同分支?