使用 Team Foundation 的用戶端物件模型來建立工作項目
您可以執行下列步驟來建立 Bug、工作和 WorkItem的其他類型:
範例
根據您建立 WorkItem 類型,大部分的必要 Fields 有預設值。如果這些值是適當的,所以您不需要明確設定它們。例如,您可以建立使用者劇本所定義 適用於 Visual Studio ALM 的敏捷式流程範本定義。對於這種 WorkItem,以及指派給 Fields 都需要狀態,原因,但有預設值。當使用者劇本時,會建立其預設狀態是「作用中」,其預設原因為「新增」,,並指派給欄位的預設值是目前的使用者。不過,需要這個標頭並沒有預設值。因此,在中,當您建立使用者劇本時,您必須設定標題。如需詳細資訊,請參閱使用者劇本 (Agile)與自訂 Team 專案和流程。下列範例會建立使用者劇本,設定標題,需要;並說明集合,就不需要。
使用這個範例
建立 C# (或 VB) 主控台應用程式。
加入下列組件的參考:
在這個範例會取代 Program.cs (或 Module1.vb) 的內容。
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace WorkItemTrackingSample
{
class Program
{
static void Main(string[] args)
{ // Connect to the server and the store, and get the WorkItemType object
// for user stories from the team project where the user story will be created.
Uri collectionUri = (args.Length < 1) ?
new Uri("http://server:port/vdir/DefaultCollection") : new Uri(args[0]);
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["DinnerNow"];
WorkItemType workItemType = teamProject.WorkItemTypes["User Story"];
// Create the work item.
WorkItem userStory = new WorkItem(workItemType)
{
// The title is the only required field that does not have a default value.
// You must set it, or you cannot save the work item.
Title = "Recently ordered menu",
Description =
"As a return customer, I want to see items that I've recently ordered."
};
// Save the new user story.
userStory.Save();
}
}
}
Imports System
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client
Module Module1
Sub Main(ByVal sArgs() As String)
' Connect to the server and the store and get the WorkItemType object
' for user stories from the team project where the user story will be created.
Dim collectionUri As Uri
If sArgs.Length = 0 Then
collectionUri = New Uri("https://Server:8080/tfs/DefaultCollection")
Else
collectionUri = New Uri(sArgs(1))
End If
Dim tpc As New TfsTeamProjectCollection(collectionUri)
Dim workItemStore As WorkItemStore
workItemStore = tpc.GetService(Of WorkItemStore)()
Dim teamProject As Project
teamProject = workItemStore.Projects("DinnerNow")
Dim workItemType As WorkItemType
workItemType = teamProject.WorkItemTypes("UserTypes")
' Create the work item
Dim userStory As New Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem(workItemType)
' The title is the only required field that does not have a default value
' You must set it, or you cannot save the item
userStory.Title = "Recently Ordered Menu"
userStory.Description = "As a return customer, I want to see items that I've recently ordered"
' Save the new user story
userStory.Save()
End Sub
End Module
注意事項 |
---|
您可以使用 WorkItemStore.BatchSave 方法,您可以將多個 WorkItem 或 WorkItemLink 在單一來回行程。 |
請參閱
工作
使用 Team Foundation 的用戶端物件模型來編輯和儲存工作項目