Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why MSTest does not copy referenced project libraries?

I have a Visual Studio solution with a C# dll project. This solution has also a test project which references the output of the C# dll project. The referenced project dll has set Copy Local = true.

If I run this test from the Visual Studio, it works fine.

But if I run it from the MSBuild task, for some reason MSTest does not copy the referenced C# dll to the MSTest working folder, so the test fails. The weird thing is, that all the other referenced libaries are copied to the MSTest working folder. And if I put a

 [DeploymentItem(@"PleaseCopyThis.dll")]

before my test method, finally it is copied to the MSTest working folder and my test runs fine.

But why does Visual Studio copy only the referenced dlls which are not part of the solution, but does not copy the referenced project dlls?

like image 928
JustAMartin Avatar asked May 07 '12 17:05

JustAMartin


1 Answers

So I have found this article: https://web-beta.archive.org/web/20140803214948/http://www.dotnetthoughts.net:80/mstest-exe-does-not-deploy-all-items/

Seems an mstest issue.

Because i just had the same issue I figured a way to fix it. In my case the referenced dll's where never actually used directly from the testproject (altough they were used by using reflection). To solve it I added a testclass with the following code:

[AssemblyInitialize]
    public static void InitializeReferencedAssemblies(TestContext context)
    {
        ObjectInAssemblyX dummy = new ObjectInAssemblyX();
        ObjectInAssemblyY dummy2 = new ObjectInAssemblyY();
    }

Now they are used so they will be copied

like image 193
amaters Avatar answered Sep 28 '22 08:09

amaters