Building Visual Studio 2010 solutions using Team Build 2008.
Now that Visual Studio 2010 and Team Foundation Server 2010 are available, we are seeing customers starting to migrate from Visual Studio 2008 to Visual Studio 2010.
But not every customer is planning on migrating all of these sources to Visual Studio 2010 and Team Foundation Server 2010 at once. For different reasons customers might not even be able to upgrade too Team Foundation Server 2010 yet.
So what is needed is a way to gradually upgrade the source base towards Visual Studio 2010.
This poses challenges for automated builds, since you would need to be able to build Visual Studio 2008 and Visual Studio 2010 solutions side by side.
With Team Foundation Server 2010 Microsoft introduced a new version of their build engine which is based on workflow. There are several workflow templates available to support automated build processes. One of those template is an upgrade template that you can use to execute your “old” builds that were created with Team Build 2008.
So when you upgrade you Team Foundation Server, those builds can still be executed.
However, for some customers, it is not an option to migrate to Team Foundation Server 2010. Although they might start using Visual Studio 2010, they will still be using Team Foundation Server 2008.
From Visual Studio 2010 you can still connect to a 2008 version of Team Foundation Server, and everything will still work. (Of course you won’t be able to use new functionality that is only available with Team Foundation Server 2010.)
So you can use Visual Studio 2010 with Team Foundation Server 2008. But what about Team Build. Can Team Build 2008 build Visual Studio 2010 solutions?
Well it turns out, default it can’t. A Visual Studio 2010 solution uses MSBuild 4.0 which has some new features that are not available in MSBuild 3.5. Furthermore it uses .NET 4.0.
When executing Team Build 2008, default MSBuild 3.5 is used.
When you try to use MSBuild 3.5 to build a Visual Studio 2010 solution, you typically could see errors in the build log like this:
Could not load file or assembly ‘file:///<Some file>‘ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. Confirm that the <UsingTask> declaration is correct, and that the assembly and all its dependencies are available.
or
error MSB4066: The attribute “Returns” in element <Target> is unrecognized.
So the basic idea to solve this, is try to execute Team Build 2008 using MSBuild 4.0.
It turns out, this is quite easy to accomplish.
Team Build 2008 uses a build service that default is installed to the: %Program Files%Microsoft Visual Studio 9.0Common7IDEPrivateAssemblies folder. In this folder you can find the service configuration file: TFSBuildService.exe.config. This file is just a .NET application configuration file and contains several keys that can be set to tweak the Team Build 2008 build service.
One of those keys is the MSBuildPath key. This key (if set) is used by the service to locate MSBuild.exe and use that version of MSBuild to execute the build process.
So by setting the MSBuildPath key to the .NET 4.0 folder (default: %WINDOWS%Microsoft.NET Frameworkv4.0.30319), we can configure the build service to use MSBuild 4.0.
After updating the configuration file just restart the Visual Studio Team Foundation Build service and your good to go!