i have a method registered like this:
[DllImport("MyApi.dll", CharSet = CharSet.Ansi)]
private static extern int SomeRandomCall();
and i added the MyApi.dll to the project with “Copy always = true” and locally everything compiles fine and the MSTest Unittests are working…
But: When i try to run the unittests manually via console, like:
mstest.exe /testcontainer:C:\mytestdll.dll
the tests are failing and that’s because mstest ( which finally executes the tests in my dll ) expects the MyApi.dll to be in its directory ( C:\Windows[…]\IDE 7\MSTest.exe )… Ok, makes sense, but:
As C# attributes require constant values as parameters, i can not use sth. like “GetCurDir() + “MyApi.dll”…
What is the best solution to handle this “dynamic path to MyApi.dll” problem?
The only thing i can think of right now is conditional compiler symbols, but that’s pretty dirty…
The
DllImportis fine as it is; what you need to do is make sure the library loader can find MyApi.dll at runtime. One way to accomplish this is with the PATH environment variable:…assuming MyApi.dll is in
C:\(not recommended).