Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio unable to run .NET Core tests

Using the latest version of Visual Studio, I'm unable to run any tests in the tests explorer. The error message in the Tests output window is:

Testhost process exited with error: It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found.
  - The following frameworks were found:
      3.1.0 at [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=2.2.0&arch=x86&rid=win10-x86
. Please check the diagnostic logs for more information.
[17/12/2019 5:46:13.908 PM] ========== Run aborted: 0 tests run (0:00:00.2418036) ==========

So it's suggestion that I need to have .net core 2.2 installed but it cannot find it. It can only find 3.1.

Let's confirm that ....

C:\Users\justi>dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.100
 Commit:    cd82f021f4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

.NET Core SDKs installed:
  2.1.604 [C:\Program Files\dotnet\sdk]
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.701 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.1.802 [C:\Program Files\dotnet\sdk]
  2.2.100 [C:\Program Files\dotnet\sdk]
  2.2.200 [C:\Program Files\dotnet\sdk]
  2.2.201 [C:\Program Files\dotnet\sdk]
  2.2.202 [C:\Program Files\dotnet\sdk]
  2.2.204 [C:\Program Files\dotnet\sdk]
  2.2.206 [C:\Program Files\dotnet\sdk]
  2.2.300 [C:\Program Files\dotnet\sdk]
  2.2.301 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]
  2.2.402 [C:\Program Files\dotnet\sdk]
  3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  <snip snip>
  Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  <snip snip>
  Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  <snip snip>
  Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  <snip snip>
  Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  <snip snip>
  Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

So it feels like I have 2.2.0 installed, as it's listed in the list of the many versions installed.

Edit

Notice this bit (emphasis mine):

  • The following frameworks were found: 3.1.0 at [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]

It looks like it's got 3.1.0 installed into .. x86 while the rest of the sdk's are installed under Program Files (x64 bit versions).

Why does it say this?

Edit 2:

  • xUnit
  • xUnit VS runner nuget is also 'installed'.
  • Visual Studio 16.4.1
like image 220
Pure.Krome Avatar asked Dec 17 '19 06:12

Pure.Krome


People also ask

How do I run a test in .NET core?

Let us now click on Run All button in Test Explorer. It will first build the code and the run the test and you will see the total time taken by the test. Let us change the test method so that we can see the output when the test fails. Let us execute the test again by clicking on the Run All button link.

Does .NET Core 3.1 work with Visual Studio 2017?

Install Visual Studio NET Core 3.1 is having long term support. Visual Studio 2017 supports . NET Core 2.1, whereas Visual Studio 2019 supports both the versions.

Does Visual Studio 2019 include .NET core?

NET Core 3.1 projects. For information on what's new in Visual Studio version 16.4, see What's New in Visual Studio 2019 version 16.4. Visual Studio for Mac also supports and includes . NET Core 3.1 in Visual Studio for Mac 8.4.


2 Answers

Change from CPU x86 to x64 … Test > Process architecture for anyCPU projects > x64

enter image description here

like image 171
Saif Avatar answered Sep 16 '22 15:09

Saif


I too had this issue. The error displayed in the Tests Output.

enter image description here

Error message snippet:

Test data store opened in 0.153 sec. ---------- Starting test discovery for requested test run ---------- Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.

  • The following frameworks were found: 3.1.9 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at:
  • https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.1.0&arch=x86&rid=win81-x86 . Please check the diagnostic logs for more information. at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(Boolean testHostExited) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler) ========== Test discovery aborted: 0 Tests found in 1.4 sec ========== Executing all tests in file: ConfigurationTests.cs ---------- Starting test run ---------- ========== Test run finished: 0 Tests run in 123.4 ms (0 Passed, 0 Failed, 0 Skipped) ==========

The issue occurred after installing .NET Core SDK 3.1.x. This change must of done something to Visual Studio Test settings.

Installations at (x86):

enter image description here

Installations at (x64):

enter image description here

I fixed it without any changes to the solution or project file. In my Test Explorer I chose the Processor Architecture for AnyCPU Projects. I changed it from x86 to x64.

enter image description here

Note: all of my .NET Core installations are x64. However, for some reason only 3.1.x existed in x86. My test project's Target framework is .NET Core 2.1, so to run the tests it needed to look in the x64 folder path.

How installations look from Add or Remove Programs:

enter image description here

like image 22
Jeremy Ray Brown Avatar answered Sep 16 '22 15:09

Jeremy Ray Brown