我正試圖在WPF/C#中編寫項目報告工具。我想訪問我們的TFS(Team Foundation Server)上的所有項目名稱,然後顯示給定項目中每個工作項目的統計信息。如何從C#中的TFS中檢索工作項目列表?
我已經得到了項目名稱,但得到實際的工作項目是什麼讓我很難。下面是我到目前爲止有:
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;
}
GetProjectInfo發回關於什麼是每個項目的一些有用的信息,但到目前爲止,它看起來像我只看到定義什麼樣的工作項包括,而不是實際 WorkItems本身。我認爲我編寫的編程看錯了地方。
從微軟的 它看起來像它的內部WorkItemTracking.Client,但不是WorkItemStore裏面,我不知道哪裏去訪問它的工作項目的定義, (http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.workitemtracking.client.workitem.aspx)。
最終版本:
這裏是我的功能的更新版本,它引用了以下的答案後。這只是返回一長串工作項目名稱與之間的新行,用於打印,這正是我想要工作的(現在)。
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;
}
我投了票,聽起來很有意思。幫助別人解決這個問題。 – mybirthname 2014-09-18 23:14:09