从vs 2017开始以编程方式连接到TFS [英] Connect to TFS programmatically from vs 2017

查看:88
本文介绍了从vs 2017开始以编程方式连接到TFS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 TFS15.x.包.

错误:

Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException:'TF30063:您无权访问" https://myproject.visualstudio.com/RpaCodeReview '

Uri Repurl = new Uri("https://myproject.visualstudio.com/RpaCodeReview");
NetworkCredential netCred = new NetworkCredential(username, password);
VssBasicCredential basicCred = new VssBasicCredential(netCred);
VssCredentials tfsCred = new VssCredentials(basicCred);
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(Repurl, tfsCred);
tpc.EnsureAuthenticated();

推荐答案

这取决于您的TFS的版本.但是,如果您尝试连接到TFS2015或TFS2017,则可以;

It depends on the version of your TFS. However, if you're trying to connect to TFS2015, or TFS2017, this will do;

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

namespace TFSConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            NetworkCredential networkCredentials = new NetworkCredential(@"Domain\Account", @"Password");
            Microsoft.VisualStudio.Services.Common.WindowsCredential windowsCredentials = new Microsoft.VisualStudio.Services.Common.WindowsCredential(networkCredentials);
            VssCredentials basicCredentials = new VssCredentials(windowsCredentials);
            TfsTeamProjectCollection tfsColl = new TfsTeamProjectCollection(
                new Uri("http://XXX:8080/tfs/DefaultCollection"),
                basicCredentials);

            tfsColl.Authenticate(); // make sure it is authenticate
        }
    }
}

我无法过分保证凭据没有问题!这个错误在我身上也发生过几次.

I cannot stress enough to ensure the credentials are a-okay! This error has occured to me a couple times too.

如果上述方法不起作用,还有另一种解决方案.

There is also another solution if the above doesn't work.

  1. 关闭Visual Studio并转到控制面板"
  2. 用户帐户->管理您的凭据(在左列)
  3. 选择"Windows凭据"
  4. 向下滚动到通用凭据"部分,然后查找您的TFS服务器连接
  5. 展开下拉菜单,然后点击编辑"
  6. 输入您的网络密码
  7. 重新启动Visual Studio并重试代码

这篇关于从vs 2017开始以编程方式连接到TFS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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