我試圖自動創建和管理TFS項目。我有以下代碼來創建一個TFS項目:創建TFS項目
try
{
Uri collectionUri = new Uri("http://TFSServer:8080");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["ProjectName"];
WorkItemType workItemType = teamProject.WorkItemTypes["ProjectNameTask"];
WorkItem userStory = new WorkItem(workItemType)
{
Title = "Recently ordered menu 2",
Description = "As a return customer, I want to see items that I've recently ordered",
State = "Proposed"
};
var invalidFields = userStory.Validate();
userStory.Save();
}
catch (Exception exception)
{
Console.WriteLine("Exception occurred: " + exception.ToString());
throw;
}
調用userStory.Validate()在invalidFields將返回一個項目,詳情:
Name: Issue Type
ReferenceName: IssueType
但是,工作項目不具備的元素鍵入IssueType。所以下面的代碼給出了編譯錯誤:
WorkItem userStory = new WorkItem(workItemType)
{
Title = "Recently ordered menu 2",
Description = "As a return customer, I want to see items that I've recently ordered",
State = "Active",
IssueType = "Some Issue"
};
錯誤提示「Can not resolve symbol'IssueType'」。這可能是因爲我沒有訪問特定TeamProject的正確dll。我認爲解決以下兩個想法中的一個可能會有所幫助:
如何爲特定的TeamProject的WorkItem獲取正確的dll?
或
是否可以將字段添加到對象類型?我試圖通過擴展WorkItem來創建一個新類,但它是名爲Microsoft.TeamFoundation.WorkItemTracking.Client的密封類。
想知道如何解決這個問題。
您可以檢查無效字段的狀態是什麼? - 例如'invalidFields [0] .Status'? – Michael
您應該使用有效的「工作項類型」而不是「ProjectNameTask」 –
@Michael invalidFields [0] .Status顯示InvalidEmpty。 – Romonov