libsodium
libsodium copied to clipboard
.NET single-file deployment behaviour has changed with the libsodium v1.0.19.1+ NuGet package
In .NET, you can bundle the runtime and libraries into a single executable, meaning users only need the executable to run your application (rather than needing to install the .NET runtime or have libraries in the same folder).
I've just been trying to create a new release of a project and have encountered an issue when doing a self-contained, single-file deployment for macOS (osx-x64 and osx-arm64). win-x64, win-x86, win-arm64, linux-x64, linux-arm64, and linux-arm don't seem to be affected. However, linux-musl-x64 has the same problem as macOS.
With v1.0.19 of the NuGet package, the libsodium library is bundled into the executable. However, with v1.0.19.1 onwards, it's not. You get a separate libsodium.dylib file (for macOS) or libsodium.a file (for linux-musl-x64) that needs to be kept with your executable for the application to work.
v1.0.19 was published to NuGet on the 19th September 2023, so a change after that date seems to have affected this functionality.
I unfortunately can't downgrade the libsodium package because my .NET libsodium binding enforces the latest version.
Steps to reproduce
- Download the latest .NET 8 SDK installer.
- Create a folder to house the project and navigate to it in the terminal.
- Create a new console project with
dotnet new console --framework net8.0. - Install the libsodium NuGet package with
dotnet add package libsodium --version 1.0.19.1. - Do a self-contained, single-file publish for macOS with
dotnet publish -c Release -r osx-x64 -p:PublishSingleFile=true -p:PublishTrimmed=true -p:PublishReadyToRun=true -p:IncludeNativeLibrariesForSelfExtract=true --self-contained true. - Navigate to the printed path (
bin\Release\net8.0\osx-x64\publish\), and you'll see there's alibsodium.dylibfile. - Delete the files in this folder and return to the original project directory.
- Change the libsodium package version with
dotnet add package libsodium --version 1.0.19. - Use
dotnet publishagain as before. - Navigate to the printed path again, and you'll see there's no
libsodium.dylibfile. This is what you want.