C# 获得;System.IO.FileLoadException“;尝试运行WorkItemTrackingHttpClient时出错
我的任务是使用asp.net从我的vsts帐户查询工作项 我使用了所有必需的库。我已经为我的vsts帐户获得了个人访问令牌,以便我可以访问我的工作项。 此外,URI是到vsts项目的链接。 运行时:C# 获得;System.IO.FileLoadException“;尝试运行WorkItemTrackingHttpClient时出错,c#,asp.net,azure-devops,workitem,C#,Asp.net,Azure Devops,Workitem,我的任务是使用asp.net从我的vsts帐户查询工作项 我使用了所有必需的库。我已经为我的vsts帐户获得了个人访问令牌,以便我可以访问我的工作项。 此外,URI是到vsts项目的链接。 运行时: 使用(workitemtrackingttpclient workitemtrackingttpclient=newworkitemtrackingttpclient(uri,_凭据)) 我得到的错误是: System.IO.FileLoadException:“无法加载文件或程序集”System.
使用(workitemtrackingttpclient workitemtrackingttpclient=newworkitemtrackingttpclient(uri,_凭据))
我得到的错误是:
System.IO.FileLoadException:“无法加载文件或程序集”System.Net.Http.Formatting,版本=5.2.2.0,区域性=中性,PublicKeyToken=31bf3856ad364e35“或其依赖项之一
我做错了什么吗?请检查项目中的
包文件夹下是否存在System.Net.Http.Formatting.dll
。没有任何其他版本冲突
e、 g:
无论我测试了什么,下面的示例代码对我有用,您都可以按照以下步骤进行尝试:
创建新项目
安装Nuget软件包:
为了这个项目
您可以从软件包管理器控制台安装它:
PM> Install-Package Microsoft.TeamFoundationServer.ExtendedClient -Version 15.112.1
3.运行以下示例代码:
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DownloadWITAttachments
{
class Program
{
static void Main(string[] args)
{
Uri uri = new Uri("https://{account}.visualstudio.com");
string PAT = "xxxxx personal access token";
string project = "Project Name";
VssBasicCredential credentials = new VssBasicCredential("", PAT);
//create a wiql object and build our query
Wiql wiql = new Wiql()
{
Query = "Select * " +
"From WorkItems " +
"Where [Work Item Type] = 'Task' " +
"And [System.TeamProject] = '" + project + "' " +
"And [System.State] <> 'Closed' " +
"Order By [State] Asc, [Changed Date] Desc"
};
//create instance of work item tracking http client
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
{
//execute the query to get the list of work items in the results
WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
//some error handling
if (workItemQueryResult.WorkItems.Count() != 0)
{
//need to get the list of our work item ids and put them into an array
List<int> list = new List<int>();
foreach (var item in workItemQueryResult.WorkItems)
{
list.Add(item.Id);
}
int[] arr = list.ToArray();
//build a list of the fields we want to see
string[] fields = new string[3];
fields[0] = "System.Id";
fields[1] = "System.Title";
fields[2] = "System.State";
//get work items for the ids found in query
var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result;
Console.WriteLine("Query Results: {0} items found", workItems.Count);
//loop though work items and write to console
foreach (var workItem in workItems)
{
Console.WriteLine("ID:{0} Title:{1} State:{2}", workItem.Id, workItem.Fields["System.Title"], workItem.Fields["System.State"]);
}
Console.ReadLine();
}
}
}
}
}
使用Microsoft.TeamFoundation.WorkItemTracking.WebApi;
使用Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
使用Microsoft.VisualStudio.Services.Common;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
命名空间下载附件
{
班级计划
{
静态void Main(字符串[]参数)
{
Uri=新Uri(“https://{account}.visualstudio.com”);
string PAT=“xxxxx个人访问令牌”;
string project=“项目名称”;
VssBasicCredential凭证=新的VssBasicCredential(“,PAT”);
//创建一个wiql对象并构建我们的查询
Wiql Wiql=新的Wiql()
{
Query=“选择*”+
“来自工作项”+
“其中[工作项类型]=‘任务’”+
“和[System.TeamProject]=”“+project+””+
“和[系统状态]‘已关闭’”+
“按[状态]Asc订购,[更改日期]说明”
};
//创建工作项跟踪http客户端的实例
使用(WorkItemTrackingTTPClient WorkItemTrackingTTPClient=new WorkItemTrackingTTPClient(uri,凭据))
{
//执行查询以获取结果中的工作项列表
WorkItemQueryResult WorkItemQueryResult=workItemTrackingHttpClient.QueryByIQlasync(wiql).Result;
//一些错误处理
if(workItemQueryResult.WorkItems.Count()!=0)
{
//需要获取工作项ID的列表并将其放入数组中
列表=新列表();
foreach(workItemQueryResult.WorkItems中的变量项)
{
列表。添加(项目Id);
}
int[]arr=list.ToArray();
//建立我们想要查看的字段列表
字符串[]字段=新字符串[3];
字段[0]=“System.Id”;
字段[1]=“系统标题”;
字段[2]=“系统状态”;
//获取查询中找到的ID的工作项
var workItems=workitemtrackingttpclient.GetWorkItemsAsync(arr,fields,workItemQueryResult.AsOf).Result;
WriteLine(“查询结果:{0}项已找到”,workItems.Count);
//循环遍历工作项并写入控制台
foreach(工作项中的var工作项)
{
Console.WriteLine(“ID:{0}Title:{1}State:{2}”、workItem.ID、workItem.Fields[“System.Title”]、workItem.Fields[“System.State”];
}
Console.ReadLine();
}
}
}
}
}
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DownloadWITAttachments
{
class Program
{
static void Main(string[] args)
{
Uri uri = new Uri("https://{account}.visualstudio.com");
string PAT = "xxxxx personal access token";
string project = "Project Name";
VssBasicCredential credentials = new VssBasicCredential("", PAT);
//create a wiql object and build our query
Wiql wiql = new Wiql()
{
Query = "Select * " +
"From WorkItems " +
"Where [Work Item Type] = 'Task' " +
"And [System.TeamProject] = '" + project + "' " +
"And [System.State] <> 'Closed' " +
"Order By [State] Asc, [Changed Date] Desc"
};
//create instance of work item tracking http client
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
{
//execute the query to get the list of work items in the results
WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
//some error handling
if (workItemQueryResult.WorkItems.Count() != 0)
{
//need to get the list of our work item ids and put them into an array
List<int> list = new List<int>();
foreach (var item in workItemQueryResult.WorkItems)
{
list.Add(item.Id);
}
int[] arr = list.ToArray();
//build a list of the fields we want to see
string[] fields = new string[3];
fields[0] = "System.Id";
fields[1] = "System.Title";
fields[2] = "System.State";
//get work items for the ids found in query
var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result;
Console.WriteLine("Query Results: {0} items found", workItems.Count);
//loop though work items and write to console
foreach (var workItem in workItems)
{
Console.WriteLine("ID:{0} Title:{1} State:{2}", workItem.Id, workItem.Fields["System.Title"], workItem.Fields["System.State"]);
}
Console.ReadLine();
}
}
}
}
}