c# - 从 vs 2017 以编程方式连接到 TFS
问题描述
我正在使用TFS 15.x. package
.
错误:
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,则可以这样做;
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
}
}
}
我不能强调以确保凭据是好的!这个错误我也发生过几次。
如果上述方法不起作用,还有另一种解决方案。
- 关闭 Visual Studio 并转到控制面板
- 用户帐户 --> 管理您的凭据(在左列)
- 选择“Windows 凭据”
- 向下滚动到“通用凭据”部分并查找您的 TFS 服务器连接
- 展开下拉菜单并单击“编辑”
- 输入您的网络密码
- 重新启动 Visual Studio 并重试代码
推荐阅读
- components - Angular 8动态添加组件“未定义的viewContainerRef”错误
- java - Spring Boot循环依赖设计问题
- r - 如何解决 R 中多元线性回归中的异方差性
- python - 一条线上的多个进口皱眉?
- javascript - 如何在我的 Angular 库中导入外部脚本?
- flutter - showAboutDialog 的颤振和翻译按钮
- python - 什么是写入文件路径的正确方法,以访问计算机上文件夹中的文档
- php - 推送者没有看到我正在广播的消息
- python - AttributeError:模块“matplotlib.cbook”没有属性“_get_data_path”
- reactjs - Material ui 条件渲染样式