C# s=new[]{“System.Id”、“System.Title”、“System.State”、“System.IterationPath”、“System.Tags”、“Microsoft.VSTS.Common.StateChangeDate”、“
s=new[]{“System.Id”、“System.Title”、“System.State”、“System.IterationPath”、“System.Tags”、“Microsoft.VSTS.Common.StateChangeDate”、“System.WorkItemType”、“Microsoft.VSTS.TCM.AutomationStatus”}; //获取查询中找到的ID的工作项 返回await-httpClient.GetWorkItemsAsync(id、fields、result.AsOf).ConfigureAwait(false); } } /// ///执行WIQL(工作项查询语言)查询以打印打开的bug列表。 /// ///组织内项目的名称。 ///异步任务。 公共异步任务PrintOpenBugsAsync(字符串项目) { var workItems=wait this.queryopenbug(项目).configurewait(false); WriteLine(“查询结果:{0}项已找到”,workItems.Count); //循环遍历工作项并写入控制台 //选择-BugID、TestCaseID、TestSuiteID{}、ResolvedDate、AutomationStatus{} foreach(工作项中的var工作项) { 字符串WorkItemType=(字符串)workItem.Fields[“System.WorkItemType”]; if(WorkItemType==“Bug”) { WriteLine(“错误是:\n\n”); 控制台写入线( “{0}\t{1}\t{2}\t{3}\t{4}”, 工作项目Id, 工作项字段[“系统标题”], 工作项字段[“系统状态”], //工作项字段[“系统相关链接”], workItem.Fields[“Microsoft.VSTS.Common.StateChangeDate”], 工作项字段[“System.WorkItemType”]); Console.WriteLine(“\n”); } 其他的 { WriteLine(“测试用例是:\n\n”); 控制台写入线( “{0}\t{1}\t{2}\t{3}\t{4}”, 工作项目Id, 工作项字段[“系统标题”], 工作项字段[“系统状态”], 工作项字段[“Microsoft.VSTS.TCM.AutomationStatus”], 工作项字段[“System.WorkItemType”]); Console.WriteLine(“\n”); }C# s=new[]{“System.Id”、“System.Title”、“System.State”、“System.IterationPath”、“System.Tags”、“Microsoft.VSTS.Common.StateChangeDate”、“,c#,tfs,tfs-workitem,C#,Tfs,Tfs Workitem,s=new[]{“System.Id”、“System.Title”、“System.State”、“System.IterationPath”、“System.Tags”、“Microsoft.VSTS.Common.StateChangeDate”、“System.WorkItemType”、“Microsoft.VSTS.TCM.AutomationStatus”}; //获取查询中找到的ID的工作项 返回await-httpClient.GetWorkItemsAsync(id、fiel
我投了赞成票,听起来很有意思。请帮助别人解决这个问题。请记住,平面查询和层次结构有不同的方法。我会检查一下,看看我是否可以让它工作。谢谢。您使用了“来自问题”,但它不应该是“来自工作项”?什么是“问题”参考资料?很有用!我研究了一些其他的查询方法(对我来说是新的),你的是我最容易使用的方法。谢谢!你可以使用“问题”或“工作项”在您的查询中,它们是相同且可互换的。如果您有其他问题,请单击按钮提问。如果您有新问题,请单击按钮提问。如果有助于提供上下文,请包含指向此问题的链接-
public const string tfsLocation = "http://whatever";
// get the top list of project names from the team foundation server
public List<string> LoadProjectList()
{
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsLocation));
var workItemStore = new WorkItemStore(tpc);
var projects = (from Project project in workItemStore.Projects select project.Name).ToList();
return projects;
}
public string GetProjectInfo(string targetProject)
{
string info = String.Empty;
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsLocation));
var workItemStore = new WorkItemStore(tpc);
foreach (Project project in workItemStore.Projects)
{
if (project.Name == targetProject)
{
info += String.Format("Project: {0}\n\n", project.Name);
info += "Work Item Types:\n";
foreach (WorkItemType item in project.WorkItemTypes)
{
info += String.Format("- {0}\n", item.Name);
info += String.Format(" - Description: {0}\n", item.Description);
info += " - Field Definitions:\n";
foreach (FieldDefinition field in item.FieldDefinitions)
{
info += String.Format(" - {0}\n", field.Name);
}
info += "\n";
}
}
}
return info;
}
public string GetProjectInfo(string targetProject)
{
string info = String.Empty;
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsLocation));
WorkItemStore workItemStore = new WorkItemStore(tpc);
Query query = new Query(workItemStore, "SELECT * FROM WorkItems WHERE [System.TeamProject] = @project", new Dictionary<string, string>() { { "project", targetProject } });
WorkItemCollection wic = query.RunQuery();
foreach (WorkItem item in wic)
{
info += String.Format("{0}\n", item.Title);
}
return info;
}
using Microsoft.TeamFoundation.WorkItemTracking.Client;
Query query = new Query(
workItemStore,
"select * from issue where System.TeamProject = @project",
new Dictionary<string, string>() { { "project", project.Name } }
);
var workItemCollection = query.RunQuery();
foreach(Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem in workItemCollection)
{
/*Get work item properties you are interested in*/
foreach(Microsoft.TeamFoundation.WorkItemTracking.Client.Field field in workItem.Fields)
{
/*Get field value*/
info += String.Format("Field name: {0} Value: {1}\n", field.Name, field.Value);
}
}
public async Task<IList<WorkItem>> QueryOpenBugs(string project)
{
var credentials = new VssBasicCredential(string.Empty, this.personalAccessToken);
// create a wiql object and build our query
var wiql = new Wiql()
{
// NOTE: Even if other columns are specified, only the ID & URL are available in the WorkItemReference
//Query = "Select [Id] " +
// "From WorkItems " +
// "Where [Work Item Type] = 'Bug' " +
// "And [System.TeamProject] = '" + project + "' " +
// "And [System.State] = 'Resolved' " +
// "Order By [State] Asc, [Changed Date] Desc",
Query = "Select [System.Id],[System.WorkItemType],[System.Title]" +
"From workitemLinks " +
"Where ([Source].[System.WorkItemType] = 'Bug' " +
"And [Source].[System.TeamProject] = '" + project + "' " +
"And [Source].[System.State] = 'Resolved' )" +
"And ([Target].[System.TeamProject] = '" + project + "' " +
"And [Target].[System.WorkItemType] = 'Test Case' )",
};
using (var httpClient = new WorkItemTrackingHttpClient(this.uri, credentials))
{
// execute the query to get the list of work items in the results
var result = await httpClient.QueryByWiqlAsync(wiql).ConfigureAwait(false);
var ids = result.WorkItemRelations.Select(item => item.Target.Id).ToArray();
// some error handling
if (ids.Length == 0)
{
return Array.Empty<WorkItem>();
}
// build a list of the fields we want to see
var fields = new[] { "System.Id", "System.Title", "System.State" , "System.IterationPath", "System.Tags", "Microsoft.VSTS.Common.StateChangeDate", "System.WorkItemType", "Microsoft.VSTS.TCM.AutomationStatus"};
// get work items for the ids found in query
return await httpClient.GetWorkItemsAsync(ids, fields, result.AsOf).ConfigureAwait(false);
}
}
/// <summary>
/// Execute a WIQL (Work Item Query Language) query to print a list of open bugs.
/// </summary>
/// <param name="project">The name of your project within your organization.</param>
/// <returns>An async task.</returns>
public async Task PrintOpenBugsAsync(string project)
{
var workItems = await this.QueryOpenBugs(project).ConfigureAwait(false);
Console.WriteLine("Query Results: {0} items found", workItems.Count);
// loop though work items and write to console
//Select - BugID , TestCaseID , TestSuiteID{} , ResolvedDate , AutomationStatus{}
foreach (var workItem in workItems)
{
string WorkItemType = (string)workItem.Fields["System.WorkItemType"];
if (WorkItemType == "Bug")
{
Console.WriteLine("The Bugs are:\n\n");
Console.WriteLine(
"{0}\t{1}\t{2}\t{3}\t{4}",
workItem.Id,
workItem.Fields["System.Title"],
workItem.Fields["System.State"],
// workItem.Fields["System.RelatedLinks"],
workItem.Fields["Microsoft.VSTS.Common.StateChangeDate"],
workItem.Fields["System.WorkItemType"]);
Console.WriteLine("\n");
}
else
{
Console.WriteLine("The TestCases are:\n\n");
Console.WriteLine(
"{0}\t{1}\t{2}\t{3}\t{4}",
workItem.Id,
workItem.Fields["System.Title"],
workItem.Fields["System.State"],
workItem.Fields["Microsoft.VSTS.TCM.AutomationStatus"],
workItem.Fields["System.WorkItemType"]);
Console.WriteLine("\n");
}