Embed dylib in Xamarin.Mac binding dll

2019-04-06 19:25发布

I'm creating bindings for Xamarin.Mac / MonoMac. I'd like to embed the dylib in the generated dll like it's done on Xamarin.iOS with the [LinkWith] attribute.

Is it possible to do that ? if so how ? Or should I load the dylib from the consuming application ? again in this case, how ?

I tried: - dropping the dylib in the Native References folder (doesn't work) - adding a [assembly: MonoMac.RequiredFramework] attribute (doesn't find the dylib)

1条回答
做自己的国王
2楼-- · 2019-04-06 19:26

I managed to load the .dylib from the consuming application by doing the following:

  • Add the .dylib to your project as Content
  • add the RequiredFrameworkAttribute:
    [assembly: MonoMac.RequiredFramework("mylib.dylib")]
  • register the assembly from the AppDelegate constructor:
    public partial class AppDelegate : NSApplicationDelegate
    {
        public AppDelegate ()
        {
            Type t = typeof(ATypeFromTheAssembly);
            MonoMac.ObjCRuntime.Runtime.RegisterAssembly (t.Assembly);
        }
    }

That still doesn't embed the .dylib in the bindings assembly, but it qualifies as progress

查看更多
登录 后发表回答