2009-06-24

Export and Import Work item queries in TFS projects

I have lately been introducing new WorkItemTypes in our TFS project to handle tests and support cases. With those new types the need for modifying the queries in the current projects was necessary. To modify a query I could have opened them in visual studio and saved them to disk and then saved them individually to each project. Since we are getting a lot of projects (60+) this would be a quite tedious task to update 10+ queries in each project individually.
To solve this administrative plague I wrote a small commandline program that allows you to export and import queries from a project.

Example
To list all queries in a project
TFSQueryUtil.exe /t https://tfsserver.domain.com:8143 /p "My Tfs Project"

This will list every Work Item Query by Scope, Name and description

To export all queries to the current folder
TFSQueryUtil.exe /t https://tfsserver.domain.com:8143 /p "My Tfs Project" /o Export /q *

This will export each query using the name of the query (plus the .wiq extension) as name of the exported file. If you want to only export one query, use the example below.
TFSQueryUtil.exe /t https://tfsserver.domain.com:8143 /p "My Tfs Project" /o Export /q "My query"

To import all *.wiq files to a project as Team queries
TFSQueryUtil.exe /t https://tfsserver.domain.com:8143 /p "My Tfs Project" /o Import /f *.wiq /qs Public

This command will use the filename (without the .wiq extension) as name for the imported query.
You can also specify a Description of the query by using the /qd switch (best for use with one query imports)

The format of the wiq files follows the WorkItemQuery schema but since the schema only includes the query and no meta data (like name, scope or description) this has to be provided as parameter switches... (Perhaps something to fix in TFS 2010)

If you need more help add the /? parameter.

I haven't released the program as open source but feel free to use it if you have need for it.
Can be downloaded from http://dan.meridium.se/TfsQueryUtil.rar
To use it you need to have Team Foundation Explorer 2008 installed. (needs the tfs dlls in the GAC).

2009-09-28 Update; small bugfix
* Now writes xml files as utf-8 (was an in consequence between xml notation and file encoding)

9 comments:

  1. exactly what I was looking for!
    thanks Dan!

    p.s. If I have the queries I want to import on a specific folder. do I need to run the command from that folder?

    ReplyDelete
  2. Well, you can run them from the same folder, or supply a path to the file if not.

    ReplyDelete
  3. Getting an exception - missing anything?

    Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
    embly 'Microsoft.TeamFoundation.WorkItemTracking.Client, Version=9.0.0.0, Cultur
    e=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The syst
    em cannot find the file specified.
    File name: 'Microsoft.TeamFoundation.WorkItemTracking.Client, Version=9.0.0.0, C
    ulture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    at TFSQueryUtil.Program.Main()

    ReplyDelete
  4. The application uses the TFS client dll:s so you need to install Visual Studio 2008 Team Explorer on the machine where you want to run it.

    ReplyDelete
  5. Just great - thank you so much!!

    ReplyDelete
  6. Any support for TFS 2010?

    ReplyDelete
  7. No. But if you are interrested you are free to fix a version for 2010. I can send you the code for the 2008 version or you can reflect the 2008 binaries if you publish the 2010 version somewhere.

    ReplyDelete
  8. Allen Feinberg22 August, 2011 19:18

    Interested in updating this to work with TFS 2010. Please send me the code at allen.feinberg@hotmail.com

    ReplyDelete
  9. Source is now published @ https://github.com/dhvik/TFSQueryUtil/

    ReplyDelete