Copyright 2017-2018 Jason Ross, All Rights Reserved

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Visual Studio is very good at migrating solutions and projects from its older versions. However everything has limits, and I’ve seen a few very rare cases where it doesn’t quite work. The main problem I’ve encountered can be recreated as follows:

Using Visual Studio 2017, load a solution and projects created in Visual Studio 2010, 2012 or 2013 using .NET 1.1 to 4.0. Once the loading/migration is complete update the .NET version for each project to .NET 4.6 or later, and add a new unit test project if the solution doesn’t already contain one. Use NuGet to install NUnit 3 as a dependency for your test project(s), and add the NUnit 3 Test Adaptor as well. Create a few NUnit unit tests in the new test project and save everything.

Open the Test Explorer window (Test | Windows | Test Explorer), and there’s a good chance that Visual Studio won’t detect any of the unit tests. There are a few suggestions on the web to solve this, but many of them didn’t work for me – maybe because the problem comes from the upgrade.

Some solutions that HAVE worked for me are:

If your projects are building as x64 or Any CPU, set the test processor architecture to x64 using:

Test | Test Settings | Default Processor Architecture | x64

Set the Build | Advanced | Debugging Information option to produce PDB debugging information for each of the test projects.

Ensure that all NUnit test projects refer to the latest versions of NUnit and the matching NUnit Test Adaptor.

Carry out a Clean / Rebuild on the solution.

You may get some strange build errors that mention previous versions of the NUnit engine. If this happens there are probably some corrupted files in your local data cache. Just close Visual Studio and open the following directory in Windows Explorer:

%USERPROFILE%\AppData\Local\Temp\VisualStudioTestExplorerExtensions

This directory will probably contain at least one subdirectory whose name matches the format:

NUnit3TestAdaptor.3.x.0

Delete all of these subdirectories. Start Visual Studio and reload your solution. Show the Test Explorer window and click on the “Run All” option. The solution should rebuild and the discover and run all of the unit tests.

If you’ve tried all of this and the Test Explorer window STILL won’t find the tests, there’s really only one thing left that I know works:

Make a backup copy of the project(s) that you migrated, delete the originals and then recreate them using Visual Studio 2017.  Copy your original .cs files back to the new directory and add them to the new projects. Copy the custom settings from the old .CONFIG file to the new one, reload the solution, and Visual Studio should now detect all of the NUnit tests and let you run them.

I’ll cover whether, when and why you should migrate .NET code as old as v 1.1 in another article.