Search code examples
c#.netmstest.net-5

MSTest Could not load file or assembly 'System.Runtime, Version=5.0.0.0' or one of its dependencies


I have a .NET 5.0 unit test project that I'm trying to execute via the command line using MSTest.

I'm using a command like the following to run the unit tests:

MSTest.exe /testcontainer:tests\bin\Debug\net5.0\UnitTestProject.dll

But I receive the following error message:

Unable to load the test container 'tests\bin\Debug\net5.0\UnitTestProject.dll' 
or one of its dependencies. Error details: System.IO.FileNotFoundException: 
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 
The system cannot find the file specified.

I've seen similar questions on here such as Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies but the answers make reference to editing an app.config file, which I do not have in my project.

Is this just a limitation of using .NET 5.0 and MSTest in the way I'm trying to? Or is there something I can do to allow MSTest to run the tests?


Solution

  • So I've done more playing around with this and because I need to use a COM library as part of the project it seems that it's not possible to use .NET 5.0/.NET core stuff in anyway.

    I did a test using .NET Framework 4.7.2 - I made a unit test solution using this version of the framework, added a COM library and ran the unit tests at the command line and all worked. The only gotcha with this was I had to use vstest.console.exe and not MSTest to run the tests.

    Using MSTest gave me the No tests to execute issue. But it seems like using vstest.console.exe is the answer to this - No tests to execute msTest