Tuesday, 10 March 2009

Team Build in TFS2008 with a VS2005 Solution and FxCop

TFS2008 can build VS2005 Solutions owing to its backwards compatibility. Unfortunatey you might run into problems if you use FxCop in VS2005 and have this integrated into your Solution build i.e. FxCop runs automatically when you compile the project(s).

Very often you will recieve code analysis errors if you run a local Team Build (a "Desktop" build) at the command line even though you didn't see those errors when building in VS2005. This seems to be related to the setting of environment variables. To run a TFS2008 Team Build at the command line it must be done with an MSBuild v3.5 command prompt but your VS2005 is geared towards MSBuild v2.0.

To solve the problem, set the Environment variable "FXCOPDIR" to be "%programfiles%\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop" and your Team Build should complete okay. Rather than setting this value universally (and trashing VS2008 builds), what I normally do is have a command file with the following contents to run my Team Builds containing VS2005 Solutions:

@echo Setting environment variables
@set FXCOPDIR=%programfiles%\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop
"%systemdrive%\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe" path\TFSBuild.proj

This sets the environment variable for the current command window and executes the Team Build. The environemnt variable means FxCop will behave as if you were in VS2005 even though you are running a TFS2008 Team Build with MSBuild v3.5.

As as an aside, note that TFS2005 can't build VS2008 Solutions. "Forwards" compatibility has provided in TFS2008 meaning TFS2008 will be able to build VS2010 Solutions. This "forwards" compatibility has been implemented by allowing you to specify the MSBuild version used by your Build Agent. See Buck Hodges post for more information:


0 comments:

About Me