Configure Unit Tests to Target .NET Framework 3.5

If you are migrating projects from previous versions of Visual Studio, you might intend to upgrade the project files to be compatible with Visual Studio 2010, but you may not want to necessarily upgrade to the latest version of the .Net Framework (v4.0) until you have properly tested compatibility.

Fair enough, but unless you have installed Visual Studio 2010 Service Pack 1, you might have some trouble with Unit Tests.  Until Service Pack 1 was released, upgrading would automatically retarget Unit Test projects to the .Net Framework v4.0 which could be a problem, especially if you have linked dependencies between projects.  To maintain compiling Unit Tests against the .Net Framework 3.5, you need to do the following:

The following MSDN article located here: http://msdn.microsoft.com/library/gg601487.aspx outlines the steps required after you have installed Visual Studio 2010 Service Pack 1 (which is a prerequisite), to allow Visual Studio Unit Test projects to target the previous version of the .Net Framework.

If you are in my position, where I’ve installed the TFS Power Tools, the devenv.exe.config file has been modified (prior to the installation of Service Pack 1) which means that you have to manually make some changes.  I highly recommend you back up the config file before making any manual changes.

There is a slight typo in the MSDN article though, at step #6, there should be a space between the “add” in the <appSettings>, i.e.

<appSettings>
     <add key="TestProjectRetargetTo35Allowed" value="true" />  
</appSettings>

..and this entry should be added after the <configSections> block (if you have one).

Then, you may add the following after the requisite <assemblyBinding> section element:

<dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.UnitTestFramework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Tip" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="10.1.0.0" newVersion="10.0.0.0"/>
      </dependentAssembly>

If you are unsure about whether your configuration is valid or not, if you are unable to connect to a TFS server, you know that you have borked your devenv.exe.config file!

Note:  I had trouble with this when I initially changed the Target Version.  When I reverted to .Net Framework v3.5, Visual Studio 2010 would force me through the Project Migration Wizard, which changed the Target Version back to .Net Framework 4.0!

Around we went in circles, until I stumbled across a Microsoft Connect entry which listed the following workaround (which I’ve tested successfully):

1. Unload the test project
2. Edit the xxxx.csproj
3. Remove {3AC096D0-A1C2-E12C-1390-A8335801FDAB}; from <ProjectTypeGuids>
4. Change the TargetFrameworkVersion to v3.5 (Save)
5. Reload the project (migration wizard still is prompted)
6. Change the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll as specified in the other workaround.

Note: you can try to re-add the ProjectTypeGuid back, but VS 2010 will convert the project to .Net 4 again when you reload the project in step 4.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.