将代码移入类库后找不到dll

我创建了一个netcoreapp2.1控制台应用程序,并希望使用本机dll。

解决方案结构:

-test
  --dependecy1.dll (needed by some.dll)
  --depedency2.dll (needed by some.dll)
  --Program.cs
  --some.dll
  --test.csproj (netcoreapp2.1 console application)

要在调试中复制dll,我将它们标记为:

<None Update="some.dll">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="dependecy1.dll">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="dependecy2.dll">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

我编写了一个静态方法并使用了DllImport(“ some.dll”):

[DllImport("some.dll")]
public static extern ulong do_dll_stuff(int arg1);

然后,我在main方法中调用了该方法,它起作用了!

现在,我想将此代码移到类库(netstandard2.0)中。 我创建了一个类库项目,将文件移至新项目中,将代码移至NativeMethods.cs中,并在上面的应用程序中对其进行了引用,一点也不花哨。我还确保以与上述相同的方式将dll复制到调试文件夹中。

解决方案结构:

-test
  --Program.cs
  --test.csproj (netcoreapp2.1 console application)
-native
  --dependecy1.dll (needed by some.dll)
  --depedency2.dll (needed by some.dll)
  --native.csproj (netstandard2.0 class library, referenced by test.csproj)
  --NativeMethods.cs
  --some.dll

If I now run my application, I get: Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'some.dll' or one of its dependencies. I checked and all 3 dlls are inside bin\Debug\netcoreapp2.1

我想念什么?

评论