带有dylib的.net标准库 - DllNotFoundException

时间:2016-06-24 12:26:30

标签: .net macos .net-core .net-core-rc2

我有一个我创建的dylib(libextern.dylib),其中包含以下内容:

int extern_test()
{
    return 123;
}

我有一个目标netstandard1.5和net451的库,其中包含:

[DllImport("libextern.dylib", EntryPoint="extern_test")]
public static extern int ExternTest();

最后,我有一个.net核心CLI应用程序,它调用库的ExternTest()。它有一个对库的项目引用:

"dependencies" : {
  "MyLibrary": {
    "version": "0.0.1",
    "target": "project"
  }
}  

如果我将libextern.dylib放入CLI项目的根目录,那么ExternTest()会按预期返回123

我希望在我的库中包含libextern.dylib,而不是将其放入我的CLI项目中。我也遵循了How to Use Native Dependencies说明(我认为其他各种指南与rc2已经过时了)但在致电DllNotFoundException时我得到ExternTest()

图书馆的project.json包含:

"buildOptions": {
  "allowUnsafe": true
},
"packOptions": {
  "files": {
    "mappings": {
      "runtimes/osx/native/": "libextern.dylib"
    }
  }
}

How to Use Native Dependencies说明省略了"mappings",但我尝试了两种方式,发现libextern.dylib需要包含在nuget包中。

我还尝试将libextern.dylib打包到另一个包中(How to Use Native Dependencies说明中的选项2),但这对我也不起作用。

我在这里做错了什么?这可能是.net core rc2的一个问题吗?

更新:使用.Net Core 1.0进行测试,行为相同。

更新2:我已将此问题记录为.Net Core github project上的问题,以防.Net Core或文档出现问题。

0 个答案:

没有答案
相关问题