Home > Back-end >  VSTest.Console.exe Could not load file or assembly Microsoft.TestPlatform.CoreUtilities
VSTest.Console.exe Could not load file or assembly Microsoft.TestPlatform.CoreUtilities

Time:03-30

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://docs.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?

CodePudding user response:

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
  • Related