Search code examples
c#.net-6.0visual-studio-2022vstestvstest.console.exe

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?


Solution

  • 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: enter image description here