Tuesday, June 10, 2008

Detecting TFS Server version from 2008 client

With the release of VSTS 2008, in certain configurations you might want to detect what version of the server your client runs against, the important configuration being 2008 client vs. 2005 TFS server, since in that configuration the feature-set on the client will be more restrictive (2005 client against 2008 server is no problem as it will not use any new features anyway).

It turns out that to get this bit of information your best bet is to use Team Build object model (the advise is courtesy of Aaron Hallberg):

IBuildServer buildServer = 
     as IBuildServer;
if (buildServer.BuildServerVersion ==  BuildServerVersion.V1)
    ; // server is 2005
else if (buildServer.BuildServerVersion == BuildServerVersion.V2)
    ; // server is 2008

If you think about it for a second, it sort of makes sense, since Team Build is the component that differs most between TFS 2005 and 2008 versions. So in the absence of general service versioning model one can use that for determining the server version.

And if you did not know it yet, Team Build object model was greatly enhanced in 2008. One of the recent discoveries for me was the custom properties bag available for builds build types in Team Build 2008 (as described in Aaron Hallberg’s blog). Using the custom properties one could provide custom categories for build types(and perhaps even expose them in Team Explorer). This is something I am planning to take a stab on (if time allows).

For Team Build OM intro there is a detailed post by Martin Woodward (it even has class diagram drawing!); and you can download the whole documentation here.

Updated: Unfortunately, it appears that custom properties I was so enthusiastic about are available for builds only, not for the build types. Thanks to Ed for correction!


Ed Blankenship said...

Unfortunately the new build properties are only available for individual builds not build definitions/types :(

I hope they make custom build properties available for build definitions too...

Ed Blankenship

eugenez said...

Darn! I was so hopeful! Thanks for correction, Ed, I have updated my overly enthusiastic post.