Team Foundation のクライアント オブジェクト モデルを使用した作業項目の作成

次の手順で WorkItems のバグ、タスク、および他のタイプを作成できます:

  1. WorkItemを作成します。

  2. 必須フィールドの値を設定します。

  3. WorkItemを保存します。

作成した WorkItem のタイプに応じて、ほとんどの Fields に既定値が表示されます。これらの値に応じて、それらをオフに設定する必要はありません。たとえば、Visual Studio ALM のアジャイル プロセス テンプレートで定義したユーザーのストーリーが作成される場合もあります。この WorkItemの型に対して、都道府県、理由、Fields に割り当てられたすべて必須ですが、既定値はです。ユーザーのストーリーを作成すると、既定は、「有効です、既定の理由は」、「」、新規予算フィールドの既定値は、期限内のユーザーです。ただし、タイトルは、要求された、既定値はありません。ユーザーのストーリーを作成すると、タイトルを設定する必要があります。詳細については、「ユーザー ストーリー (アジャイル)」および「チーム プロジェクトとプロセスのカスタマイズ」を参照してください。次の例では、ユーザーのストーリー;を作成します 必要な肩書きを、;設定 要求を設定しない説明。

ユーザー ストーリー

この例を使用します。

  1. C# (または) VB コンソール アプリケーションを作成します。

  2. 次のアセンブリへの参照を追加します。

  3. この例で 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 のクライアント オブジェクト モデルを使用した作業項目の編集と保存

関連項目

BatchSave

概念

Team Foundation のクライアント オブジェクト モデルを使用した作業項目トラッキングの拡張

Team Foundation のクライアント オブジェクト モデルを使用したさまざまな種類の作業項目のコードの記述