VisualStudio unit test does not find my dll with P / Invoke. How can i fix this?

I am working on Windows 7 with Visual Studio 2008.

I have a .NET assembly that calls calls to my native DLL with P / Invoke. I created a separate .NET unit test project in my Visual Studio solution, which tests the assembly by making various calls to it. However, when the unit test makes a call in the assembly, and the assembly makes the call using P / Invoke, it cannot find the native DLL.

When I write a standalone .NET console application, there is no problem. The assembly can use P / Invoke and successfully find the DLL.

I can make the unit test work by calling LoadLibrary with an absolute DLL path before using the assembly. However, this approach is ugly and requires an absolute path that will be problematic for other users.

In short, my question is: how can I specify or change the DLL search path that is used when running the Visual Studio unit test?

Any help would be greatly appreciated.

Regards, Dan

+3
source share
3 answers

It seems that the problem is that your native DLL is not deployed with your unit test DLL files. This is not an unusual problem, since the managed DLL does not reference its own in the metadata, so the deployment packages do not know how to deploy them.

The most appropriate solution is to fix the deployment rather than changing the paths of the DLL search. This is a unit test problem. Can you tell us what framework you use so that we can help you?

+3

Visual Studio 2008, DeploymentItemAttribute

, . , . .

. VS2008.

+3

post build :

xcopy /Y /S "$(SolutionDir)\ShredLibraries\*" "$(TargetDir)"

msdn docs: https://msdn.microsoft.com/en-us/library/ms182475.aspx

0

Source: https://habr.com/ru/post/1760785/


All Articles