问题
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:
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
来源:https://stackoverflow.com/questions/15271877/embed-dylib-in-xamarin-mac-binding-dll