Crear un elemento de trabajo usando el modelo de objetos de cliente para Team Foundation
Se pueden crear errores, tareas y otros tipos de WorkItem mediante los siguientes pasos:
Ejemplo
Según cuál sea el tipo de WorkItem que cree, la mayoría de los Fields obligatorios tienen valores predeterminados. Si estos valores son adecuados, no tiene por qué establecerlos expresamente. Por ejemplo, puede crear un caso de usuario según se explica en MSF for Agile Software Development para Visual Studio ALM. Para este tipo de WorkItem, los Fields Estado, Motivo y Asignado a son todos obligatorios, pero tienen valores predeterminados, puesto que, cuando se crea un caso de usuario, el estado predeterminado es "Activo", el motivo predeterminado es "Nuevo" y el valor predeterminado del campo Asignado a es el usuario actual. Con todo, el título es obligatorio y carece de un valor predeterminado, de modo que se deberá definir cuando se cree un caso de usuario. Para obtener más información, vea Caso de usuario (Agile) [redirigido] y Visión de un extremo a otro sobre lo que se puede configurar y personalizar en Visual Studio TFS. En el siguiente ejemplo se crea un caso de usuario, se establece el título (obligatorio) y, también, la descripción (que no es obligatoria).
Para usar este ejemplo
Cree una aplicación de consola de C# (o VB).
Agregue referencias a los siguientes ensamblados:
Reemplace el contenido de Program.cs (o Module1.vb) por este ejemplo.
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 generally the only required field that doesn’t have a default value.
// You must set it, or you can’t save the work item. If you’re working with another
// type of work item, there may be other fields that you’ll have to set.
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("User Story")
' Create the work item
Dim userStory As New Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem(workItemType)
' The title is generally the only required field that doesn’t have a default value.
' You must set it, or you can’t save the work item. If you’re working with another
' type of work item, there may be other fields that you’ll have to set.
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
Nota
Se puede guardar más de un WorkItem o WorkItemLink en un solo recorrido de ida y vuelta con el método WorkItemStore.BatchSave.
Vea también
Tareas
Editar y guardar elementos de trabajo usando el modelo de objetos de cliente para Team Foundation