microsoft / testfx

MSTest framework and adapter
MIT License
721 stars 253 forks source link

"Adding the references and satellite assemblies to the deployment items list" doesn't copy all references #3679

Open decriptor opened 1 month ago

decriptor commented 1 month ago

The tl;dr; is that the unmanaged references from nuget packages aren't copied to the TestResults\Deploy_***\out directory.

In my case, I'm trying to test my ML library that uses the Microsoft.ML.OnnxRuntime.DirectML nuget: image

My unit tests run and pass if I run them in Visual Studio or use the new mstest nugets that generate {AssemblyName}.exe. If I try to run them from the console (and CI) using vstest.console.exe it fails to load the native assemblies.

From what I can tell so far, when vstest.console.exe runs it tries to find all of the references and copy them to the out folder it finds the managed references from the nugets. ie,

DeploymentManager: Reference:D:\source\X\tests\X\Y.ML.Tests\bin\Debug\net472\OpenCvSharp.dll 
DeploymentManager: Reference:D:\source\X\tests\X\Y.ML.Tests\bin\Debug\net472\Microsoft.ML.OnnxRuntime.dll

image

vstest.console.exe, Adding the references and satellite assemblies to the deployment items list
vstest.console.exe, AssemblyDependencyFinder.GetDependentAssemblies: start.
vstest.console.exe, UnitTestAdapter: Using configuration file D:\source\X\tests\X\Y.ML.Tests\bin\Debug\net472\Y.ML.Tests.exe.config to setup appdomain for test source Y.ML.Tests.exe.
vstest.console.exe, AssemblyDependencyFinder.GetDependentAssemblies: Using config file: 'D:\source\X\tests\X\Y.ML.Tests\bin\Debug\net472\Y.ML.Tests.exe.config'.
vstest.console.exe, AssemblyDependencyFinder.GetDependentAssemblies: Created AppDomain.
vstest.console.exe, AssemblyDependencyFinder.GetDependentAssemblies: loaded the worker.
vstest.console.exe, AssemblyDependencyFinder.GetDependentAssemblies: unloading AppDomain...
vstest.console.exe, AssemblyDependencyFinder.GetDependentAssemblies: unloading AppDomain succeeded.
vstest.console.exe, DeploymentManager: Source:D:\source\X\tests\X\Y.ML.Tests\bin\Debug\net472\Y.ML.Tests.exe has following references

However, things like onnxruntime.dll or OpenCvSharpExtern.dll are not copied over to the out folder.

I haven't had much luck trying to google. I'm hoping that I'm missing something simple.

decriptor commented 1 month ago

I've worked around this by adding this to my test case: [DeploymentItem(@"onnxruntime.dll")] [DeploymentItem(@"onnxruntime.lib")] [DeploymentItem(@"OpenCvSharpExtern.dll")]

Evangelink commented 1 month ago

Hi @decriptor,

I will investigate the issue (most likely next week).

Evangelink commented 1 month ago

@decriptor is moving to the new platform (MSTest runner - what you called {AssemblyName}.exe) a possiblity? There is a class of issues that are really hard to fix with VSTest platform and we are not actively investing into it when there is a viable solution with the new platform.

decriptor commented 1 month ago

@Evangelink I think so. Is the future {AssemblyName}.exe and vstest.console.exe will be deprecated?

Our current situation is that we moved as many projects as we could to sdk projects and then netstandard2.0 as much as possible. We are slowly trying to migration from net472 to net8.0 (or whatever is current when we get there). Also, we are trying to upgrade from Azure DevOps 2020 server to at least Azure DevOps 2022 server.

Evangelink commented 1 month ago

vstest.console.exe will be deprecated?

This would be an ideal but this is for sure going to take years.

The new platform (MSTest runner) doesn't require SDK style project (when you have it, it's easier as you can rely on MSTest.Sdk that greatly simplifies your project).

Would it be possible for you to create a small repro that I could use and debug to really pin point the issue and see what's possible on my end.