C#连接到TFS并检查工作项状态

时间:2016-04-18 23:41:54

标签: c# tfs

我正在尝试连接到TFS并检查工作项的状态。但是,每次执行代码时,都会收到以下错误消息:

Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll

中发生未处理的“System.DllNotFoundException”类型异常

其他信息:无法加载DLL'Microsoft.WITDataStore32.dll':找不到指定的模块。 (HRESULT异常:0x8007007E)

在代码命中时发生: WorkItemStore workItemStore =(WorkItemStore)tfs.GetService(typeof(WorkItemStore));

我引用了以下DLL:      - Microsoft.TeamFoundation.Client      - Microsoft.TeamFoundation.WorkItemTracking.Client      - Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader

这是我的代码。

    private static void connectToTfs(int executionType)
    {
        Console.WriteLine("Starting to work on TFS");

        // Supply the credentials of the user who will be impersonated to create the bug 
        ICredentials credentials = CredentialCache.DefaultNetworkCredentials;

        TfsTeamProjectCollection tfs =
            new TfsTeamProjectCollection(new Uri("http://URL:8080/Team"), credentials);

        if (tfs.HasAuthenticated == true)
        {
            Console.WriteLine("Connected to TFS");
            WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

            switch (executionType)
            {
                case 1:
                    //create query
                    string queryString = "Select [State] From WorkItems Where [ID] = '4123567' ";

                    //Dictionary for storing variables
                    Dictionary<string, string> variables = new Dictionary<string, string>();
                    variables.Add("ID", "State");

                    Query query = new Query(workItemStore, queryString, variables);
                    WorkItemCollection results = query.RunQuery();

                    foreach (KeyValuePair<string, string> kvp in variables)
                    {
                        Console.WriteLine("ID {0} state is {1}", kvp.Key, kvp.Value);
                    }

                    break;
             }
       }
    }

1 个答案:

答案 0 :(得分:0)

This可能有解决方法。

建议手动找到Microsoft.WITDataStore的GAC32版本,将其重命名为Microsoft.WITDataStore32并添加到项目的bin文件夹中