labstreaminglayer / liblsl-Csharp

C# bindings for liblsl
MIT License
28 stars 18 forks source link

Nuget Package #2

Open vpenades opened 4 years ago

vpenades commented 4 years ago

I think it could be interesting if the library could be available as a nuget package.

I've seen it mostly targets Unity, but there's life out of it...

tstenner commented 4 years ago

I've pushed a first attempt here: https://github.com/labstreaminglayer/liblsl-Csharp/tree/nuget

The main problem is packaging / unpacking the native libraries somewhere the runtime looks when DllImporting liblsl and so far I haven't found anything that works.

glopesdev commented 3 years ago

@tstenner The current "official" way is to call SetDllDirectory or more generally simply depend on OS dynamic library resolution (e.g. using the PATH environment variable) to point to the appropriate runtimes folder inside the package: https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime/8861895#8861895

This has so far been done by detecting at runtime what platform the application is running under, then finding the location of the nuget package in the cache, and pointing the PATH to that folder before calling the P/Invoke layer. Some libraries opt to change their entire interop to use LoadLibrary instead, but that raises a number of maintenance issues IMO.

In .NET 5.0 there is NativeLibrary which can be used to leverage fast calls, but then you lose backwards compatibility with .NET framework. So far, the best tradeoff is still to simply use straight P/Invoke and setting the PATH environment variable.

I've pushed a new PR that expands the NuGet package declaration to include package tags, project URL and package license information, together with some documentation explaining how to build the package.