【发布时间】: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