如何成功连接到 TFS 2010 工作项存储?

发布于 2025-01-02 08:29:12 字数 2078 浏览 2 评论 0原文

我尝试了两种连接到我们正在运行的 TFS 服务器的工作项存储的方法。尝试 A 是连接到配置服务器并使用 GetService() 方法。这总是返回 null。

尝试 B 是连接到 TfsTeamProjectCollection 并使用 GetService() 方法或将项目集合传递到 WorkItemStore 构造函数中。在尝试 B 时,我收到一个异常,指出“错误 HRESULT E_FAIL 已从对 COM 组件的调用中返回”。我能找到的唯一信息似乎表明存在一些权限问题,但我已确认我已作为对整个项目集合具有读取访问权限的用户进行了身份验证,并且我通过 VS 2011 开发预览进行了适当的连接和干预。

这是我的连接方式...

    public TfsConfigurationServer GetConfigurationServer()
    {
        Uri tfsUri = new Uri(configs.TfsUri);
        TfsConfigurationServer server = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri, credProvider);
        server.Authenticate();
        if (server.HasAuthenticated == false)
            throw new InvalidOperationException("You can't authenticate against the tfs instance.");
        return server;
    }

    public TfsTeamProjectCollection GetProjectCollectionInstance(string projectCollectionName)
    {
        Uri tfsUri = new Uri(configs.TfsUri + "/" + projectCollectionName);         
        TfsTeamProjectCollection collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri, credProvider);
        collection.Authenticate();
        if (collection.HasAuthenticated == false)
            throw new InvalidOperationException("You can't authenticate against the tfs instance.");
        return collection;
    }

这是我尝试获取 WorkItemStore 的方式(愚蠢的代码来说明问题)...

    public WorkItemProvider()
    {
        if (workItems == null)
            workItems = ServerProvider.ServerInstance.GetService<WorkItemStore>();
        if (workItems == null)
            workItems = ServerProvider.ProjectCollectionInstance.GetService<WorkItemStore>();
        if (workItems == null)
            workItems = new WorkItemStore(ServerProvider.ProjectCollectionInstance);
        if (workItems == null)
            throw new NullReferenceException("Couldn't load work item store.");
    }

我与服务器不在同一域中,但我正在以身份验证具有 ICredentialsProvider 的域用户,并且我已确认我已通过该用户的身份验证。任何指示都会有帮助。

I've tried two ways of connecting to the workitemstore for the TFS server we're running. Attempt A was to connect to the configuration server and use GetService<WorkItemStore>() method. This always returns null.

Attempt B was to connect to the TfsTeamProjectCollection and use the GetService<WorkItemStore>() method or pass the project collection into the WorkItemStore constructor. On attempt B, I get an exception stating "Error HRESULT E_FAIL has been returned from a call to a COM component." The only info I can find on that seems to indicate some permissions problem, but I've confirmed I'm authenticated as a user with read access to the whole project collection and I connect and meddle appropriately via VS 2011 dev preview.

Here's how I'm connecting...

    public TfsConfigurationServer GetConfigurationServer()
    {
        Uri tfsUri = new Uri(configs.TfsUri);
        TfsConfigurationServer server = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri, credProvider);
        server.Authenticate();
        if (server.HasAuthenticated == false)
            throw new InvalidOperationException("You can't authenticate against the tfs instance.");
        return server;
    }

    public TfsTeamProjectCollection GetProjectCollectionInstance(string projectCollectionName)
    {
        Uri tfsUri = new Uri(configs.TfsUri + "/" + projectCollectionName);         
        TfsTeamProjectCollection collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri, credProvider);
        collection.Authenticate();
        if (collection.HasAuthenticated == false)
            throw new InvalidOperationException("You can't authenticate against the tfs instance.");
        return collection;
    }

and here's how I'm trying to get the WorkItemStore (silly code to illustrate the problem)...

    public WorkItemProvider()
    {
        if (workItems == null)
            workItems = ServerProvider.ServerInstance.GetService<WorkItemStore>();
        if (workItems == null)
            workItems = ServerProvider.ProjectCollectionInstance.GetService<WorkItemStore>();
        if (workItems == null)
            workItems = new WorkItemStore(ServerProvider.ProjectCollectionInstance);
        if (workItems == null)
            throw new NullReferenceException("Couldn't load work item store.");
    }

I'm not on the same domain as the server, but I'm authenticating as a domain user with an ICredentialsProvider and I've confirmed I'm authenticated as that user. Any pointers would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单调的奢华 2025-01-09 08:29:12

检查这是否满足您的需要:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace GetsWorkItem
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://<TFS>:8080/tfs/<COLLECTION>"));
            WorkItemStore workItemStore= (WorkItemStore) teamProjectCollection.GetService(typeof (WorkItemStore));

            WorkItem workItem = workItemStore.GetWorkItem(1234);
        }
    }
}

Check if this does what you need:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace GetsWorkItem
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://<TFS>:8080/tfs/<COLLECTION>"));
            WorkItemStore workItemStore= (WorkItemStore) teamProjectCollection.GetService(typeof (WorkItemStore));

            WorkItem workItem = workItemStore.GetWorkItem(1234);
        }
    }
}
旧人哭 2025-01-09 08:29:12

我相信这篇文章也许能够回答你的问题。它表示,如果您以稍微不同的方式实例化 WorkItemStore,您将得到不同的异常:

System.TypeInitializationException:“Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore”的类型初始值设定项引发异常。 —> System.IO.FileLoadException:混合模式程序集是针对运行时版本“v2.0.50727”构建的,如果没有附加配置信息,则无法在 4.0 运行时中加载。

该修复是一个简单的 web.config 更改,通过添加以下内容:

<?xml version="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>

希望这有帮助!当我遇到同样的错误时为我工作。

I believe this article might be able to answer your question. It says that if you instantiate your WorkItemStore in a slightly different way, you'll get a different exception:

System.TypeInitializationException: The type initializer for ‘Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore’ threw an exception. —> System.IO.FileLoadException: Mixed mode assembly is built against version ‘v2.0.50727′ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

The fix is a simple web.config change, by adding the following:

<?xml version="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>

Hope this helps! Worked for me when I was getting the same error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文