MSTest 找不到 TestAdapter.dll

MSTest cannot find TestAdapter.dll

我正在使用内置的 Visual Studio 测试工具(菜单中的 Test -> Run -> etc)。我刚开始遇到一个问题,当我尝试 运行 测试

时出现以下错误

[3/29/2018 1:39:14 PM Error] System.IO.FileNotFoundException: C:\Users\brubin\AppData\Local\Temp\VisualStudioTestExplorerExtensions\MSTest.TestAdapter.1.1.18/build/_common/Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll at Microsoft.VisualStudio.TestWindow.Controller.TestPlatformProvider.PerformShadowCopy(IEnumerable'1 testExtensions)

后面是一些错误

Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

当我查看文件夹 C:\Users\brubin\AppData\Local\Temp\VisualStudioTestExplorerExtensions\MSTest.TestAdapter.1.1.18/build/_common/ 时,该文件夹中没有文件。但是,我没有故意更改我的测试设置的任何内容,几天前它还在工作,所以我不知道为什么它会停止工作。

我的项目正在使用 MSTest.TestFramework (MSTest V2) 版本 v1.2 NuGet 包。

我注意到可能导致此问题的一件事是,如果我转到 Tools -> Extensions and Updates,我会看到我的 Microsoft Visual Studio 测试平台已于几天前更新,即 3/23 (我想那是我安装 Visual Studio 更新的时候)。但是,如果这损坏了某些东西,我不知道去哪里查看损坏的东西,或者如何修复它。

对我来说,清除 VisualStudioTestExplorerExtensions 文件夹并重新启动 Visual Studio(根据 this github issue)就可以了。就我而言,它包含两个用于不同版本 MSTest.TestAdapter 的文件夹,我不知道这是否相关。

对于遇到这个问题的任何其他人,问题是因为我的一些测试项目没有包含 MSTest.TestAdapter NuGet 包。我将 MSTest.TestAdapter 包添加到我所有的测试项目中,现在问题似乎已经永久解决了。

这是 Visual Studio 中的错误。将 Visual Studio 升级到版本 15.7。 https://developercommunity.visualstudio.com/content/problem/222892/filenotfoundexception-microsoftvisualstudiotestpla.html

是的,您需要更新所有测试项目的 "MsTest.TestAdapter"。最简单的方法是右键单击主解决方案并单击管理 nuget 包。然后 select “已安装”选项卡,查看每个测试项目上是否安装了 TestAdapter。如有必要,您可以将 TestAdapter 更新到最新版本。然后重新启动 Visual Studio 它应该可以工作了。

我花了整整一周的时间来解决同样的问题。直到昨天,我才意识到从控制台进行 运行ning 测试可以节省时间。令我惊讶的是,我刚刚将我的所有项目(位于 "OneDrive" 文件夹内)移到了另一个位置。现在,它就像一个魅力!我所有的测试 运行 来自 Visual Studio IDE。我不知道移动文件是否与它有任何关系,但你可以试一试。

重新安装所有解决方案的 Nuget 包为我解决了这个问题。

请在程序包控制台上运行此命令:

Update-Package -reinstall

然后再试,或者重启VS,再试。

参考:https://ardalis.com/force-nuget-to-reinstall-packages-without-updating/