Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio 2019 run tests in dotnet core 1.0 even though my projects target dotnet core 2.2?

I have a solution with 2 projects, one of which is a test project. Both projects target dotnet core 2.2:

<TargetFramework>netcoreapp2.2</TargetFramework>

I am using Visual Studio 2019 (version 16.1.1). When I click "Run all" in test explorer, it outputs this warning in output window:

[5/28/2019 10:25:40 PM Informational] ------ Run test started ------
[5/28/2019 10:25:40 PM Warning] Test run will use DLL(s) built for framework .NETCoreApp,Version=v1.0 and platform X64. Following DLL(s) do not match framework/platform settings.
MyApp.UnitTests.dll is built for Framework 2.2 and Platform AnyCPU.
Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.

[5/28/2019 10:25:41 PM Informational] ========== Run test finished: 3 run (0:00:01.167997) ==========

The tests do run, and finish successfully. But I am wondering about how to get rid of this warning.

I added a .runsettings file with following settings, but I still see the same warning.

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <RunConfiguration>
    <TargetFrameworkVersion>FrameworkCore10</TargetFrameworkVersion>
  </RunConfiguration>
</RunSettings>

Changing FrameworkCore10 to FrameworkCore22 (or netcoreapp2.2) throws a huge exception. Top few lines of the exception:

[5/28/2019 10:41:30 PM Error] System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.TestWindow.Controller.RequestConfiguration.GroupTestContainersConfigByFrameworkAndArchitecture(IEnumerable`1 testContainersConfig, IXPathNavigable runSetting)
   at Microsoft.VisualStudio.TestWindow.Controller.TestRunConfiguration.<GetAllCriteriaQueues>d__64.MoveNext()
   at Microsoft.VisualStudio.TestWindow.Controller.TestRunRequest.<CreateRequests>d__23.MoveNext()
   at Microsoft.VisualStudio.TestWindow.Controller.Request.<RunRequests>d__95.MoveNext()
   --- End of inner exception stack trace ---

Note that the same projects work fine in Visual Studio 2017, without the need of any runsettings file whatsoever.

like image 671
Turbo Avatar asked May 29 '19 05:05

Turbo


2 Answers

This is not an answer, but posting to help others landing here.

Visual Studio team has acknowledged the issue and is looking into fixing this. It's best to follow it here:

  • Issue at VS Developer Community: https://developercommunity.visualstudio.com/content/problem/579073/test-discovery-reporting-dlls-do-not-match.html
  • Related issue on GitHub: https://github.com/MicrosoftDocs/visualstudio-docs/issues/1305
like image 199
Turbo Avatar answered Sep 26 '22 08:09

Turbo


I had the problem after upgrading from a netframework project to netcore.

Using VS Enterprise 16.3.8, cleaning the solution as well as deleting all temporary folders such as bin and obj helped me to get the tests running in the desired netcore version.

Edit:
As a sidenote VS has sometimes problems, when changing the target framework. After changing it deleting the bin / obj could sometimes be your last escape.

like image 28
Ba5t14n Avatar answered Sep 24 '22 08:09

Ba5t14n