Sunday, January 22, 2012

Target framework for test project

Issue

After upgrading Visual Studio solution from 2008 (10.0) to 2010 (11.0) version, all test projects are automatically upgraded to using .Net Framework 4.0. If you try to set it to other values (3.5 or 2.0), it prevents this action by showing the following message:

---------------------------
Microsoft Visual Studio
---------------------------
Attempted re-targeting of the project has been canceled. You cannot change the specified .NET framework version or profile for a test project.
---------------------------
OK
---------------------------

Cause

Issue is reported to Microsoft Connect and closed as Won't fix. They did not explain why in the discussion, but I think this is due to some difficulty with Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll library compatibility.

Solution/Workaround

It works if you created your testing project by Visual Studio, but did not actually use VS testing engine and included other testing engine (e.g. NUnit). You just need to remove the guid for Test projects ({3AC096D0-A1C2-E12C-1390-A8335801FDAB} - see list) from ProjectTypeGuids property of the project file (*.??proj). This project type is not required for unit testing by other engines.

Otherwise, if you use Microsoft Visual Studio unit testing, try using some combination of workarounds described here.

Used links: