Crear un elemento de trabajo usando el modelo de objetos de cliente para Team Foundation
Puede crear errores, tareas, y otros tipos de s de WorkItemsiguiendo estos pasos:
Ejemplo
Según el tipo de WorkItem que crea, la mayoría de Fields necesario tiene valores predeterminados.Si estos valores son adecuados, no tiene que establecer explícitamente.Por ejemplo, podría crear un caso de usuario como se define en Plantilla de proceso para Agile para Visual Studio ALM.Para este tipo de WorkItem, requieren pero tiene el estado, de Resolución, y de Asignado a Fields todo valores predeterminados.Cuando se crea un caso de usuario, el estado predeterminado es “activo”, el motivo predeterminado es “New”, y el valor predeterminado de Asignado a colocar es el usuario actual.Sin embargo, el título es obligatorio y no tiene ningún valor predeterminado.Por consiguiente, debe establecer el título cuando se crea un caso de usuario.Para obtener más información, vea Caso de usuario (Agile) y Personalizar procesos y proyectos de equipo.El ejemplo siguiente crea un caso de usuario; establece el título, se requiere que; y establece la descripción, que no se necesita.
Para utilizar 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) con 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 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
[!NOTA]
Puede guardar más de un WorkItem o WorkItemLink en una única acción de ida y vuelta mediante el método de WorkItemStore.BatchSave .
Vea también
Tareas
Editar y guardar elementos de trabajo usando el modelo de objetos de cliente para Team Foundation