Today when writing tests for a new project built using VS2010 I had an interesting problem:
NUnit would not run my unit tests because the assembly that contained my unit tests was compiled using a newer version of the .NET runtime.
There are several solutions to solve this issue from downgrading my project to use earlier version of .NET to migrate my unit tests to MSTest but luckily for me no such drastic move was needed.
The new NUnit (2.5.x) have support for running tests using .NET 4 it’s just hidden inside a pile of xml.
To run .NET 4.0 test assembly add the lines below to the relevant config file, so if you’re using NUnit.exe update nunit.exe.config or if you’re using nunit-console.exe use nunit-console.exe.config – you get the point.
- Under <configuration> add:
<startup><requiredRuntime version=”v4.0.21006″ /></startup>
- Under <runtime> add:
<loadFromRemoteSources enabled=”true” />
I’m using the latest VS2010 RC2 If you have a different version of Visual Studio installed change the version value to the version of the .NET 4 installed on your machine – look at C:\Windows\Microsoft.NET\Framework to find out which version you have.