During the recent (and ongoing) development of the "Scrum for Team System" 2010 template (version 3.0 Beta for those counting) we needed to export team project queries. A new facility of Team Explorer 2010 is the ability to "Save As" when editing the query and chose the local file system. Pretty neat.
However, when you have a large suite of queries, this is very time consuming. You also have to strip out the server and project details from the resulting files before you can load them into a template. Being a developer at heart, the thought of repeating a single tedious action more that twice fills me with an inner dread. So I have written a simple command line utility that extracts all the queries from the specified project, maintaining the project query folder structure and stripping off any project specific content.
The "tfsQueryExport.exe" utility (attached below) requires 3 command parameters:
- Usage:
tfsQueryExport [tfs url] [project name] [output folder]
- Example:
tfsQueryExport "http://tfshost:8080/tfs/DefaultCollection" "Project 1" "c:\temp\Queries"
The output will be written to the specified output folder within a directory named after the project.
Note: This utility makes use of the TFS 2010 Team Explorer assemblies, so you will needed TE installed before it will work.
Geeky Moment: I also needed to create the template query specification fragment in order to list the queries in our template, so I took a little time travel pill and wrote a batch file to traverse the exported query folder structure:
@ECHO OFF
cd.> Queries.txt
FOR /D %%D IN (.\*) DO (
FOR /D %%X IN ("%%D\*") DO (
(ECHO ^<QueryFolder name="%%X"^> >> Queries.txt)
FOR /R . %%A IN ("%%X\*.wiq") DO (
ECHO ^<Query name="%%A" fileName="%%A"^> >> Queries.txt
)
(ECHO ^</QueryFolder^> >> Queries.txt)
)
)
PAUSE
It's not perfect. You have to strip out the unwanted folder paths and file extensions. It only handles a single folder depth too, but I just fancied a little nostalgia! Please feel free to suggest some improvments, it's been a while since I wrote in DOS.
Crispin.