Click here to Skip to main content
12,350,121 members (26,522 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as



TFS 2010 Work Item Seed: TFS Work Item at a predefined number

, 5 Dec 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
TFS 2010 Work Item Seed: TFS Work Item at a predefined number

This week, my customer had a requirement to have all new work items created to have an ID greater than 40,000. They have another system that stores tickets and they don't want any conflict.

There have been a number of ways to achieve this through a database change, but it is not supported by Microsoft. This means that if you make the change and mess it up, you are on your own.

In order to provide a supported way of doing this you need to use the API, and that is an interesting problem. We are going to have to use the API to create a specific number of work items, but we don't really want those work items hanging around.

We could:

  1. Create a new Team Project
  2. Add 40,000 work items
  3. Delete the Team Project

But there should be a neater way and to that end, let's connect to a Team Project that we can use to create the work items in.

Dim projectPicker As New TeamProjectPicker(TeamProjectPickerMode.SingleProject, False)

If Not projectPicker.SelectedTeamProjectCollection Is Nothing Then


    _Store = projectPicker.SelectedTeamProjectCollection.GetService(Of WorkItemStore)()
    _ProjectInfo = projectPicker.SelectedProjects(0)

End If

We can use the TeamProjectPicker class that the product team kindly provided to show the built in dialog to select a Team Project Collection and a a Team Project.


Figure: Getting the user to select a Team Project could not be easier

This dialog has some different modes depending on what you are trying to achieve. You can set it to select either a Team Project Collection, one Team Project or many Team Projects.

Public Enum TeamProjectPickerMode
    ' Fields
    MultiProject = 2
    NoProject = 0
    SingleProject = 1
End Enum

Now that we have access to a WorkItemStore and know what Team Project to use to create the work items, we can start creating work items.

Dim wi As WorkItem = project.WorkItemTypes(0).NewWorkItem
wi.Title = String.Format("Seedgen {0} : _
	Created by Hinshlabs TFS Work Item Seed Generator", i)
wi.Description = String.Format("As a TFS Admin I want to have all new work items _
	start at a number {0} larger than the current number", _WorkItemCount)

This may fail as all I am doing is picking the first work item type that is available. A better solution would be to select the first work item type in the “Requirement” category, or to give the user a list to select whatever he wants. This is just a throw away, one time bit of code, so as long as it works…

Just in case any of these work items are left at the end, I have added a default Title and Description.

Once we have created this work item, we need to immediately delete it. Now, this is something that can’t be done using the UI, but can be done in code.

Dim WioError As IEnumerable(Of WorkItemOperationError)
Dim ids As Integer() = {Convert.ToInt32(wi.Id)}
WioError = _Store.DestroyWorkItems(ids)

A tiny bit of code that solves a big problem. In versions before TFS 2010, this could only be done using the Power Tool, but the product team has seen the light and added it into the core product. Remember that Deleting a Work Item CAN’T be undone and once it is gone, it is gone.

I have wrapped all of this into a ViewModel that can be used in an MVVM WPF application.

Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client
Imports Microsoft.TeamFoundation.Server
Imports GalaSoft.MvvmLight.Command
Imports GalaSoft.MvvmLight.Threading
Imports System.Windows.Threading
Imports System.Threading

''' <span class="code-SummaryComment"><summary>

I have tried to comment at least some of this, but again this is proof-of-concept code with no warranty and could do with lots of improving.

This is a supported method of incrementing the Work Item ID to any number you like. It will take a while to get to 40,000 but I have added a “Time taken” calculation and it looks like you can increment the top ID by around 600 every minute.


Figure: As you can see, I am an artist

I have been running this with a local TFS running on my Windows 7 laptop with SQL Express so actual times may not be as advertised.

How stable is this? Well, to be honest, not very. I threw this together quickly, but with all my debugging, killing and general mashing it only left 1 erroneous work item that will need to be deleted manually.


Figure: One lonely work item that did not get destroyed

To delete this errant work item, you can:


You can get your work item ID from 0 to 40000 in around 40 minutes with this app which solves the immediate problem.


Technorati Tags: ,,

<iframe marginwidth="0" marginheight="0" src="""" frameborder="0" width="1" scrolling="no" height="1" />


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Martin Hinshelwood
Instructor / Trainer naked ALM
United States United States

About the Author: Martin has worked with many customers in government, finance, manufacturing, health and technology to help them improve their processes and deliver more. He provides management and technical consulting that intends to expose processes and practices to gain transparency, uncover impediments to value delivery and reduce cycle-time as part of an organisations path to agility. Martin is a Professional Scrum Trainer as well as a Visual Studio ALM MVP and Visual Studio ALM Ranger. He writes regularly on, and speaks often on Scrum, good practices and Visual Studio ALM.

You can get in touch with Martin through naked ALM.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 5 Dec 2010
Article Copyright 2010 by Martin Hinshelwood
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid