简体   繁体   中英

VSTest.Console.exe Could not load file or assembly Microsoft.TestPlatform.CoreUtilities

I'm trying to set up a C# project with the latest version of Visual Studio, 2022; this is with.Net 6 on Windows 10. It's a simple console program, and I've set up the project and a corresponding unit test project basically following the steps described in https://learn.microsoft.com/en-us/visualstudio/test/walkthrough-creating-and-running-unit-tests-for-managed-code?view=vs-2022 so I've got something isomorphic to that tutorial project.

And the unit tests work fine when run from within Visual Studio.

Now I want to also run them from the command line.

vstest.console bin\Debug.net6.0\foo.dll

gives

Testhost process exited with error: Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. File name: 'Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at Microsoft.VisualStudio.TestPlatform.TestHost.Program.Main(String[] args). Please check the diagnostic logs for more information.

Looks like the toolchain is failing to find one of its own libraries? Is there some option I need to be specifying?

Make sure that foo.dll is the project which contain the tests and reference MSTest.TestFramework if you follow convention naming, this should be fooTests.dll

vstest.console bin\Debug\net6.0\fooTests.dll

in the example you mention the following line will throw error

vstest.console ..\BankTests\bin\Debug\net6.0\Bank.dll

While this will run normally

vstest.console ..\BankTests\bin\Debug\net6.0\BankTests.dll

After upgrading from.Net 5 to.Net 6, I had to face the same issue.

Add the following two lines to your.csproj file to fix the issue.

<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<GenerateRuntimeConfigDevFile>true</GenerateRuntimeConfigDevFile>

Example: 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM