如何使用非服务用户帐户以编程方式连接到TFS Online [英] How to connect to TFS Online programmatically with non-service user account

查看:47
本文介绍了如何使用非服务用户帐户以编程方式连接到TFS Online的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么,你是b $ b $
连接到Azure托管的TFS项目集合作为特定用户的正确方法是什么,即不作为服务帐户没有任何UI提示?



我尝试了下面建议的代码(来自另一个论坛帖子),但它不起作用。



使用System;

使用System.Net;

使用Microsoft.TeamFoundation.Client;

使用Microsoft.VisualStudio.Services .Common;
$


命名空间SourceControlTest

{

   课程计划

    {

        static void Main(string [] args)

        {

           试试
            {

                var netCred = new NetworkCredential(@"MyVS2017UserName",@"MyVS2017Password");

                var winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(netCred);

                var vssCred = new VssCredentials(winCred);

                var tpc = new TfsTeamProjectCollection(new Uri(" https://ourprojectcollectionname.visualstudio.com"),vssCred);

                tpc.Authenticate();

            }¥b $ b            catch(例外e)

            {

                Console.WriteLine(e);

            }


            Console.ReadLine();

        }¥b $ b    }
}


我得到例外:



Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException:TF30063:您无权访问https://x.visualstudio.com/。 ---> System.Net.WebException:远程服务器返回错误:(401)未经授权。

    at System.Net.HttpWebRequest.GetResponse()

   在Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.SendRequestAndGetResponse(HttpWebRequest的WebRequest的,引发WebException&安培;引发WebException)

    ---内部异常堆栈跟踪结束---

    at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.SendRequest()

    at Microsoft.TeamFoundation.Client.Channels.TfsHttpRequestChannel.Request(TfsMessage message,TimeSpan timeout)

   在Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation操作,对象[]参数,时间跨度超时,对象[]&安培;输出)

    at Microsoft.TeamFoundation.Framework.Client.LocationWebService.Connect(Int32 connectOptions,Int32 lastChangeId,Int32 features)

    at Microsoft.TeamFoundation.Framework.Client.FrameworkServerDataProvider.Connect(ConnectOptions connectOptions)

    at Microsoft.TeamFoundation.Framework.Client.FrameworkServerDataProvider.Authenticate()

    at Microsoft.TeamFoundation.Client.TfsConnection.Authenticate()

   在SourceControlTest.Program.Main(字串[] args)在C:\SourceControl\X.Deployment\Source\BuildProcess\SourceControlTest\Program.cs:线18


有人能够帮我弄清问题是什么......?b


我确实尝试找到一个特定于TFS的论坛但是他们看起来都是存档... 请随时将此问题移至更合适的位置...



$








$

解决方案

你好jeanangeo,


根据您的描述,您希望以编程方式连接到TFS Online。 / span>


请问你能用吗?这个方法并进行测试:


使用
Microsoft TeamFoundation 客户端 ;


使用
Microsoft VisualStudio 服务 客户端 ;


var u =
new
Uri " https:// {your account} .visualstudio。 com" );


// VssCredentials C =新VssCredentials(新Microsoft.VisualStudio.Services.Common.VssBasicCredential(的String.Empty," juwlupdpprcwqqonrpr7h3qnerozvin2oaokmcfsl22bpqtlhcda"));


var c =
new
VssClientCredentials ();


c.Storage =
new
VssClientCredentialStorage storageKind
" VssApp2" ;
storageNamespace
" VisualStudio" );


TfsTeamProjectCollection _tfs =
new
TfsTeamProjectCollection (u,c);


_ tfs.EnsureAuthenticated();


上述方法将弹出登陆框登录,如果您使用评论行,则需要指定个人访问令牌或备用帐户。


< span style ="line-height:107%; font-family:'Segoe UI',sans-serif; font-size:10pt">>>

我确实尝试找到一个特定于TFS的论坛,但它们似乎都已归档...  
请随意移动这个问题到一个更合适的位置......


由于TFS论坛已被锁定,TFS的讨论已经移动。我建议你在
上发布你的问题 Stack Overflow ,然后你会得到TFS成员的支持。


问候,


Judyzh


Hi there,

What is the correct way to connect to a TFS project collection hosted in Azure as a specific user i.e. NOT as a service account without any UI prompt?

I tried the suggested code below (from another forum post) but it does not work.

using System;
using System.Net;
using Microsoft.TeamFoundation.Client;
using Microsoft.VisualStudio.Services.Common;

namespace SourceControlTest
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var netCred = new NetworkCredential(@"MyVS2017UserName", @"MyVS2017Password");
                var winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(netCred);
                var vssCred = new VssCredentials(winCred);
                var tpc = new TfsTeamProjectCollection(new Uri("https://ourprojectcollectionname.visualstudio.com"), vssCred);
                tpc.Authenticate();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.ReadLine();
        }
    }
}

I get the exception:

Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: You are not authorized to access https://x.visualstudio.com/. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()
   at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.SendRequestAndGetResponse(HttpWebRequest webRequest, WebException& webException)
   --- End of inner exception stack trace ---
   at Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.SendRequest()
   at Microsoft.TeamFoundation.Client.Channels.TfsHttpRequestChannel.Request(TfsMessage message, TimeSpan timeout)
   at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters, TimeSpan timeout, Object[]& outputs)
   at Microsoft.TeamFoundation.Framework.Client.LocationWebService.Connect(Int32 connectOptions, Int32 lastChangeId, Int32 features)
   at Microsoft.TeamFoundation.Framework.Client.FrameworkServerDataProvider.Connect(ConnectOptions connectOptions)
   at Microsoft.TeamFoundation.Framework.Client.FrameworkServerDataProvider.Authenticate()
   at Microsoft.TeamFoundation.Client.TfsConnection.Authenticate()
   at SourceControlTest.Program.Main(String[] args) in C:\SourceControl\X.Deployment\Source\BuildProcess\SourceControlTest\Program.cs:line 18

Would someone be able to help me figure out what the issue is...?

I did try and find a TFS specific forum but they all appear to be archived...  Please feel free to move this question to a more suitable location...







解决方案

Hi jeanangeo,

According to your description, you want to connect to TFS Online programmatically.

Could you please use this method and have a test:

using Microsoft.TeamFoundation.Client;

using Microsoft.VisualStudio.Services.Client;

var u = new Uri("https://{your account}.visualstudio.com");

//VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "juwlupdpprcwqqonrpr7h3qnerozvin2oaokmcfsl22bpqtlhcda"));

var c = new VssClientCredentials();

c.Storage = new VssClientCredentialStorage(storageKind: "VssApp2", storageNamespace: "VisualStudio");

TfsTeamProjectCollection _tfs = new TfsTeamProjectCollection(u, c);

_tfs.EnsureAuthenticated();

Above method will eject the landing box login, if you use the comment line, it need to specify personal access token or alternate account.

>> I did try and find a TFS specific forum but they all appear to be archived...  Please feel free to move this question to a more suitable location...

Since the TFS forums have been locked, the discussion for TFS has moved. I recommend you post your issue on Stack Overflow, and then you would get support from TFS members.

Regards,

Judyzh


这篇关于如何使用非服务用户帐户以编程方式连接到TFS Online的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆