A custom MSBuild task to retrieve a workspace name and owner based on a given local path

UPDATE Jan 26, 2013 – I received a comment that the download link is broken.  When I checked the link URL I realized that the ZIP file was hosted on my old ISP and was never migrated.  I don’t have a copy available anywhere, sorry.  I would however recommend that you check out the Community TFS Build Extensions project.

I’m working on hooking my code generation utility MSBuild task into my VB project files. I’ve create a new BuildType called “CodeGenDebug” which I will use in my Continuous Integration build. I’d also like to give my devs the ability to run this build fromthe VS IDE if they have to update a large number of code generated files, say when a core template changes. It all looked good until I noticed that the build from the IDE doesn’t give you the current workspace name as a parameter. This will cause a problem since the code generation utility checks out all of the code gen specific files prior to doing the generation.
My first thought was to just assume that the machine name (which is available) is the workspace name since the default name given to a workspace is the machine name. AllI had to do was mandate that the devs couldn’t have more than 1 workspace and that it had to be named the same as their workstation name. Needless to say, that didn’t go over very well…
So I discussed it with some of the members of my team and happened to mention it to Mike Ruminer, who happens to be hanging around my office this week trying to get us hapless buffoons going with TFS (we aren’t really hapless buffoons, but I’ve been trying to work that phrase into my blog for a month now…maybe I’ll use it at a meeting soon {evil grin}). Anyway, he wondered why I just don’t ask TFS for the workspace name since I have the path available. So I did.
Here is a custom MSBuild task that will give you the workspace name and workspace owner name for a given local path. It will thrown an exception if it can’t find a matching workspace or if the local path isn’t mapped. Look at the included .proj file for the syntax and UsingTask declaration.
The zip file contains the source code, binaries and a test MSBuild project file.