对Visual Studio Team Services(TFS Online)的身份验证从VS2010中的WinFor
本文关键字:身份验证 VS2010 WinFor 中的 Online Studio Visual Team Services TFS | 更新日期: 2023-09-27 18:30:47
我正在尝试在VisualStudio 2010中创建一个独立的WinForm,该WinForm访问团队服务代码库并将最新文件返回到我的本地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();
我最终在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/
首先,删除代码中的此行NetworkCredential iCred = new NetworkCredential(emailUsername, password);
。
然后,您可能需要删除Windows凭据(控制面板->管理Windows凭据)中的帐户和密码。现在您可以输入用户名和密码。