Yor*_*dan 8 .net c# tfs basic-authentication azure-devops
我试图从我在.NET上编写的Windows服务访问https://visualstudio.com(以前称为https://tfs.visualstudio.com,http://www.tfspreview.com).
我想使用新的基本身份验证,但我找不到办法.
我发现很多链接到博客帖子Team Foundation Service更新 - 8月27日,但它正在使用Team Explorer Everywhere Java客户端进行TFS.
是否有新版本的TFS .NET对象模型支持基本身份验证?
顺便说一下,我已经连续登录了服务帐户.这个答案非常有用.
Gra*_*day 12
首先,您需要在计算机上至少安装Visual Studio 2012 Update 1.它包括Microsoft.TeamFoundation.Client.dll与BasicAuthCredential班级的更新程序集.
以下是代码来自Buck的博客文章如何连接到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);
}
}
}
Run Code Online (Sandbox Code Playgroud)