Thursday, 22 April 2010

Visual Studio 2010 and Team City (MSBuild 4.0 and NUnit)

I’ve recently started upgrading some of our projects to use Visual Studio 2010.  As we use Team City as our continuous integration environment I had to install .NET 4.0 on the server as the Visual Studio msbuild (csproj and sln files are msbuild files) won’t build using .NET 3.5 or below correctly.  Team city however can’t tell that you’ve upgraded, so you need to add an environment variable to each project you upgrade:

MSBuild set to %system.DotNetFramework4.0_x86_Path%

This does the trick (after much searching to find that), but once you’re done if you’re using nUnit then you’re in for another world of hurt.  Team City 5 will support .NET 4.0 but not the version that comes with Visual Studio 2010 (at the time of writing).  Visual Studio 2010 will install v4.0.30319 but nUnit will only work with up to v4.0.30128 (again at the time of writing, hopefully JetBrains release a new version soon).

You can TELL the dotNet plugin to work with the correct framework, it’s a pain in the ….. well it’s messy, but it works. 

Open the <server>\webapps\root\update\plugins directory and copy down the file.  Unpack it and open the dotnetPlugin\bin directory.  Open each file matching the wildcard JetBrains.TeamCity.PlatformProcessRunner.v4.0*.exe.config and modify the startup section to show the following:

<supportedRuntime version="v4.0.20506"/>
<supportedRuntime version="v4.0.21006"/>
<supportedRuntime version="v4.0.30128"/>
<supportedRuntime version="v4.0.30319"/>

You should probably already have the first three, I just had to add the last one.  Once you’ve done this your code should work after you tell the nUnit team city plugin to use .Net 4.0 instead of 2.0.

<Exec Command="$(teamcity_dotnet_nunitlauncher) v4.0 x86 NUnit-2.4.8  Project.Tests\bin\$(Configuration)\Project.Tests.dll" />

Underlined above.

Both those bits of information were available on the net, but hard to find and both found seperately.  Hopefully they help someone.


Eugene said...

Try TeamCity 5.1, there will no patching required to make .NET v4.0 tests run

Odd said...

I didn't know it was out, thanks I'll give it a shot.

Jeffry said...

I have a question, how are you publishing solutions through TeamCity? I was previously using Web Deployment Projects in .NET 3.5 and VS 2008, but have yet to crack the code as to how to do it in VS 2010 and .NET 4.0

Odd said...

Hey Jeffry,

We use different approaches for each project. For our basic ones we use WEb Deployment Projects which is currently in BETA for 2010 but works very well. For more advanced projects we use custom msbuild scripts and the web deployment tool (not to be confused with web deployment projects).

Some more information here: