【问题标题】:Authentication to Visual Studio Team Services (was TFS Online) fails from WinForms code in VS2010VS2010 中的 WinForms 代码对 Visual Studio Team Services(以前是 TFS Online)的身份验证失败
【发布时间】:2016-04-23 22:43:43
【问题描述】:

我正在尝试在 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();

【问题讨论】:

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


    【解决方案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/

    【讨论】:

      【解决方案2】:

      首先,删除代码中的这一行 NetworkCredential iCred = new NetworkCredential(emailUsername, password);

      那么您可能需要删除 Windows 凭据中的帐户和密码(控制面板 -> 管理 Windows 凭据)。现在你可以输入用户名和密码了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多