-
Notifications
You must be signed in to change notification settings - Fork 77
Description
The way libplctag.NativeImport packages the runtimes is not standard. NativeImport extracts the appropriate native library to disk at runtime.
It was originally done this way to facilitate compliance with libplctag's LGPL license (requiring a way for end users to substitute the native binary). Now libplctag is dual licensed with MPL so this is not required.
This is a problem because some applications can not write into the application directory (UWP apps). As far as I understand, this is a security feature. Snaps (snapcraft.io) also feature an immutable application directory, so the technique of extracting the library at runtime won't work.
Most .NET packages that ship native libraries ship them in a way that the native library is extracted as part of the build process (rather than at runtime). See https://dev.to/jeikabu/nupkg-containing-native-libraries-1576
@timyhac 's expertise in developing nuget packages is limited, and the non-standard way was selected because it wasn't straightforward how to do it the standard way but still keep maximum compatibility:
- Absolutely need example of how to include native libraries NuGet/Home#6648
- Guide for packaging C# library using P/Invoke to per-architecture and/or per-platform C++ native DLLs NuGet/Home#8623
A limitation of the "extract at runtime" procedure is that applications require permissions to write to disk. Depending on the application, this may not be practical (e.g. all UWP applications have highly restricted access to filesystems). If an application requires file system access purely for this feature, it would be an unusual experience for end-users "why does this need access to disk? I can understand why it needs access to local network, but what files is it accessing?!"
The requirements for the "pre-packaged native library" feature are:
- Support any .NET runtime that can run .NET Standard 2.0
- linux/windows/macos/iOS/Android/etc..
- both .NET Core and .NET Framework
- Support for over-riding the binary (in case of testing a pre-release or other customised binary)
- Support for platforms where the binary is not packaged (e.g. ARM)
- Support as a referenced package (i.e. should exhibit this behaviour whether it is directly referenced, or indirectly as part of primary libplctag.NET package)
- Updating the nuget package also updates the native library.
Update 27/6/2024: Microsoft has released some guidance on including Native files into packages, including for .NET Framework.