【问题标题】:Why does Visual Studio 2019 run tests in dotnet core 1.0 even though my projects target dotnet core 2.2?为什么Visual Studio 2019在Dotnet Core 1.0中运行测试即使我的项目目标Dotnet Core 2.2?
【发布时间】:2019-10-14 16:04:49
【问题描述】:

我有一个包含 2 个项目的解决方案,其中一个是测试项目。这两个项目都针对 dotnet core 2.2:

<TargetFramework>netcoreapp2.2</TargetFramework>

我正在使用 Visual Studio 2019(版本 16.1.1)。当我在测试资源管理器中单击“全部运行”时,它会在输出窗口中输出此警告:

[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) ==========

测试确实运行并成功完成。但我想知道如何摆脱这个警告。

我添加了一个具有以下设置的 .runsettings 文件,但我仍然看到相同的警告。

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

将 FrameworkCore10 更改为 FrameworkCore22(或 netcoreapp2.2)会引发巨大的异常。异常的前几行:

[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 ---

请注意,相同的项目在 Visual Studio 2017 中运行良好,无需任何运行设置文件。

【问题讨论】:

  • 我无法在 VS 2019 和针对 Core 2.2 和 3.0 的 xUnit 中重现这一点。这可能是 Visual Studio MSTest 适配器的问题。您是否尝试过使用dotnet test 运行测试?如果可以,则说明问题出在 VS 测试适配器中,或者至少不在控制台测试运行程序中
  • 您是否尝试过更新测试项目的 NuGet 包? Microsoft.NET.Test.Sdk 以及您使用的任何测试框架都将添加为 NuGet 包。也许问题已经在较新的版本中得到解决。或者你可以做 .NET Core 团队自己做的事情并使用 xUnit
  • @PanagiotisKanavos 项目中的所有 nuget 包都在最新的稳定更新中。 Microsoft.NET.Test.Sdk 在 16.1.0 上。 MSTest.TestAdapter 和 MsTest.TestFramework 在 1.4.0 上。我会尝试 dotnest 测试并报告。有一件事是,这是一个 azure function app 项目,也是一个普通的测试项目。
  • 现在面临完全相同的问题。我能在网上找到的只是尝试将 .runsettings 中的框架版本设置为“.NETCoreApp,Version=v2.2”。但似乎 vs 无论如何都忽略了这些设置......
  • 也看到了同样的问题。更新到最新的 VS2019、xunit v2.4.1 和 Microsoft.NET.Test.Sdk v16.1.1

标签: c# .net-core visual-studio-2019 vstest


【解决方案1】:

可能是那台机器上没有安装 2.2 dot net framework。

这里是Link,可以下载框架。

【讨论】:

  • 1.0 甚至不再受支持
  • 你可以做一件事设置框架 1.0 并重新安装 1.0 包。
【解决方案2】:

这不是答案,而是发帖帮助其他人登陆这里。

Visual Studio 团队已确认此问题并正在研究解决此问题。最好在这里关注:

【讨论】:

    【解决方案3】:

    从网络框架项目升级到 netcore 后我遇到了问题。

    使用 VS Enterprise 16.3.8,清理解决方案以及删除所有临时文件夹(例如 binobj)帮助我在所需的 netcore 版本中运行测试。

    编辑:
    作为旁注,VS 在更改目标框架时有时会出现问题。更改后删除 bin / obj 有时可能是你最后的逃生。

    【讨论】:

      猜你喜欢
      • 2021-09-10
      • 2017-05-15
      • 2021-03-02
      • 1970-01-01
      • 2021-11-17
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多