为什么 Visual Studio 2019 运行 在 dotnet core 1.0 中测试,即使我的项目以 dotnet core 2.2 为目标?
Why does Visual Studio 2019 run tests in dotnet core 1.0 even though my projects target dotnet core 2.2?
我有一个包含 2 个项目的解决方案,其中一个是测试项目。这两个项目都以 dotnet core 2.2 为目标:
<TargetFramework>netcoreapp2.2</TargetFramework>
我正在使用 Visual Studio 2019(版本 16.1.1)。当我在测试资源管理器中单击 "Run all" 时,它会在输出 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) ==========
测试 运行,并成功完成。但是我想知道如何摆脱这个警告。
我添加了一个具有以下设置的 .运行settings 文件,但我仍然看到相同的警告。
<?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 年工作正常,不需要任何 运行 设置文件。
可能是那台机器没有安装 2.2.net 框架。
这里是Link,你可以下载框架
这不是一个答案,而是为了帮助其他人登陆这里而发布的。
Visual Studio 团队已确认此问题并正在研究解决此问题。最好跟着这里:
我在从 netframework 项目升级到 netcore 后遇到了问题。
使用 VS Enterprise 16.3.8,清理解决方案并删除所有临时文件夹,例如 bin
和 obj
帮助我在所需的 netcore 中获得测试 运行版本。
编辑:
作为旁注,VS 在更改目标框架时有时会出现问题。更改后删除 bin
/ obj
有时可能是你最后的逃避。
我有一个包含 2 个项目的解决方案,其中一个是测试项目。这两个项目都以 dotnet core 2.2 为目标:
<TargetFramework>netcoreapp2.2</TargetFramework>
我正在使用 Visual Studio 2019(版本 16.1.1)。当我在测试资源管理器中单击 "Run all" 时,它会在输出 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) ==========
测试 运行,并成功完成。但是我想知道如何摆脱这个警告。
我添加了一个具有以下设置的 .运行settings 文件,但我仍然看到相同的警告。
<?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 年工作正常,不需要任何 运行 设置文件。
可能是那台机器没有安装 2.2.net 框架。
这里是Link,你可以下载框架
这不是一个答案,而是为了帮助其他人登陆这里而发布的。
Visual Studio 团队已确认此问题并正在研究解决此问题。最好跟着这里:
我在从 netframework 项目升级到 netcore 后遇到了问题。
使用 VS Enterprise 16.3.8,清理解决方案并删除所有临时文件夹,例如 bin
和 obj
帮助我在所需的 netcore 中获得测试 运行版本。
编辑:
作为旁注,VS 在更改目标框架时有时会出现问题。更改后删除 bin
/ obj
有时可能是你最后的逃避。