Why MSTest does not copy referenced project libraries?

 ̄綄美尐妖づ 提交于 2019-11-30 01:15:20

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/10486113/why-mstest-does-not-copy-referenced-project-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!