Improve finding frameworks in DllImport
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 123
Description
Currently DllImports to a function in a framework needs to use this as the library:
```cs
[DllImport ("@rpath/MyFramework.framework/MyFramework")]
static extern void MyFunction ();
```
This is rather complex and not intuitive for .NET developers, and it gets complicated for NuGets when the same code is supposed to work on multiple platforms, when other platforms use a different library name (it's not possible to compile the code once and share it).
One idea would be to introduce a build step that rewrites the library for DllImports if there's a matching framework included in the build.
Say a DllImport has LibraryName="MyFramework", and a `MyFramework.framework/MyFramework` is included in the build - then we'd rewrite the DllImport to point to `@rpath/MyFramework.framework/MyFramework` instead.
Downsides:
* It might slow down debug builds (since all the methods in all assemblies would have to be scanned (although we might have a list of assemblies we know we don't have to scan, so it would only be user assemblies).
An existing solution is for customers to use the NativeLibrary API (https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.nativelibrary?view=netcore-3.1), but it's not very discoverable. It also adds runtime cost for something we can do at compile time.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.