Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR builds upon #17, further improving NuGet packaging.
To respect @glopesdev's work in #17, this PR is directly based on @glopesdev's branch. Therefore, when merging, please consider:
If possible, option 1 is preferred, and I will handle the rebase.
Main Updates in This PR
Following the discussion in Add support for nuget package generation #17, the package name and project files have been changed to LSL.Net, and NuGet packaging for LSL.Net has been improved.
Added packaging support for liblsl native libraries.
The benefit of this approach is that users can install the liblsl dynamic library automatically via NuGet, without manually downloading
lsl.dll/so/dylib
from the liblsl release page and configuring their project to copy them to the output directory. This makes LSL.Net truly cross-platform and supports both .NET Framework and modern .NET.The packaging logic for LSL.Net.runtime is mainly in
src/LSL.Net.runtime/Directory.Build.targets
, which uses MSBuild'sDownloadFile
to fetch the liblsl dynamic libraries andUnzip
to extract them. The_CollectNativeLibs
target handles the final packaging.src/LSL.Net.runtime/Directory.Build.targets
also includes special handling for .NET Framework, inspired by SkiaSharp.When referenced in .NET Framework projects, the following logic ensures
lsl.dll
is correctly located:Added a new example, LSLVer, for simple testing.
Improved the GitHub Actions workflow.
Discussion Points
There are generally two approaches to packaging native libraries:
Approach 1
Package both the native libraries and the C# binding library into a single NuGet package.
Approach 2
The downside of approach 1 is that the package size becomes very large. Considering all platforms (
android
,ios
,linux
,macOS
,windows
) and architectures (arm
,arm64
,x64
,x86
), the liblsl dynamic libraries could total tens of megabytes.Therefore, this PR follows the packaging strategy of NetVips, SkiaSharp, SQLitePCLRaw, and opencv.net, packaging native libraries separately instead of bundling them with the C# binding library.
Dependency Question:
Should the C# binding library depend on the native library NuGet packages?
For LSL.Net, the question is: Should LSL.Net depend on LSL.Net.runtime.win-x64, LSL.Net.runtime.win-x86, and future packages like LSL.Net.runtime.linux-x64?
This PR follows NetVips' approach (NetVips on NuGet) and does not make LSL.Net depend on LSL.Net.runtime.
However, SkiaSharp (NuGet) does make its binding library depend on native packages (
SkiaSharp.NativeAssets.macOS
,SkiaSharp.NativeAssets.Win32
).Naming Question:
The native library NuGet packages are named LSL.Net.runtime.[rid]. Do you agree with this naming?
Some reference packages:
NetVips.Native.win-x64
,NetVips.Native.win-x86
SkiaSharp.NativeAssets.macOS
,SkiaSharp.NativeAssets.Win32
runtime.native.System.IO.Ports
,runtime.osx-x64.runtime.native.System.IO.Ports
,runtime.linux-x64.runtime.native.System.IO.Ports
Versioning Issue
I prefer keeping the version number of
liblsl-Csharp
in sync withliblsl
. For example, if the currentliblsl
version is 1.16.2, thenliblsl-Csharp
should also be 1.16.2.Since we haven't officially released it yet and there are still many areas for improvement, we can consider first releasing a preview version: 1.16.2-preview.1.
Unresolved Issues
Linux-x64, OSX-x64, OSX-arm64 packaging not yet added
.tar.bz2
, which is used forliblsl-1.16.2-OSX_amd64.tar.bz2
in the liblsl releases page.ProjectReference vs. PackageReference
As noted in dotnet/sdk#19929, when example projects reference LSL.Net.runtime via ProjectReference, they cannot locate the liblsl dynamic libraries at runtime.
Current workaround:
src\LSL.Net.runtime\CopyNativeLib.targets
, which copies the native libraries to the output directory.x86/x64/AnyCPU
.LD_LIBRARY_PATH
/DYLD_LIBRARY_PATH
.Alternative solution:
Best solution:
Next Steps
.pdb
files for unmanaged code debugging.lsl.dll
without MSVC dependency, so users don't need the Microsoft VC++ runtime.Many of these improvements are already implemented in SharpLSL, so they should not be too difficult to integrate.