VS2010中的WinForms代码对Visual Studio Team Services(TFS Online)进行身份验证失败

时间:2016-01-18 17:02:34

标签: c# winforms visual-studio-2010 tfs azure-devops

我正在尝试在VisualStudio 2010中创建一个独立的WinForm,它访问Team Services代码库并将最新文件返回到我的本地Windows文件夹。但是,我不断收到以下错误:

TF30063: You are not authorized to access the server.
TF30064: You are not authorized to access the server.

唯一有效的访问方式是使用我不想要的默认凭据,因为它们只能在打开visual studio时使用,并且tfs已登录 - 无法将其作为独立的winform使用

这是我的代码:

string teamProjectCollectionUrl = "https://xxxx.visualstudio.com/DefaultCollection";
NetworkCredential iCred = new NetworkCredential(emailUsername, password);

TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(new Uri(teamProjectCollectionUrl), iCred);
VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>();
Workspace workspace = versionControlServer.GetWorkspace(sourcePath);

//For Initial Setup
WorkingFolder workfolder = new WorkingFolder(@"$\project\subproject", sourcePath);
workspace.CreateMapping(workfolder);

workspace.Get();

2 个答案:

答案 0 :(得分:1)

我最终使用Visual Studio 2013中的备用凭据执行此操作:

NetworkCredential netCred = new NetworkCredential("altUserName", "altPassword");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;

TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(new Uri(teamProjectCollectionUrl), tfsCred);
teamProjectCollection.Authenticate();
teamProjectCollection.EnsureAuthenticated();

VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>();

Workspace workspace = versionControlServer.GetWorkspace(localPath);

// WorkingFolder workfolder = new WorkingFolder(serverPath, localPath);
// workspace.CreateMapping(workfolder);

GetStatus getStatus = workspace.Get();

请参阅以下超级有用的链接:

https://blogs.msdn.microsoft.com/buckh/2013/01/07/how-to-connect-to-tf-service-without-a-prompt-for-liveid-credentials/

https://blogs.msdn.microsoft.com/buckh/2012/03/10/team-foundation-version-control-client-api-example-for-tfs-2010-and-newer/

答案 1 :(得分:0)

首先,在代码中删除此行NetworkCredential iCred = new NetworkCredential(emailUsername, password);

然后您可能需要删除Windows凭据中的帐户和密码(控制面板 - &gt;管理Windows凭据)。现在您可以输入用户名和密码。