Getting libsodium to work on Windows
libsodium requires the Visual C++ Redistributable for Visual Studio 2015-2022 on Windows. This dependency is included in the .NET SDK. When publishing software, there are three ways to deal with this:
Install this as part of your application setup/as a package manager dependency.
Ask the user to manually install this.
Bundle the
vcruntime140.dll
file with your executable.
If you want your program to be portable (e.g. self-contained), you have to take the third approach. This can be done using the following steps:
Download the
VisualCppRedist_AIO_x86_x64.exe
file from the latest release of this GitHub repo.Use 7-Zip to extract the downloaded executable (e.g. right click, hover over 7-Zip, and click Extract to "VisualCppRedist_AIO_x86_x64\").
In the extracted folder, navigate to
2022
,x86
and/orx64
(depending on which platform your application targets),System
orSystem64
, and copy thevcruntime140.dll
file(s) to your project folder.Add the
vcruntime140.dll
file(s) as embedded resources in your project.Write some code that extracts the relevant (x86 or x64) file to the location of your executable or to the directory where the
libsodium.dll
file is located when your application starts.Test that libsodium in your application works/doesn't throw a
PlatformNotSupportedException
on a Windows machine that doesn't have the Visual C++ Redistributable installed (e.g. in Windows Sandbox or a virtual machine).
Last updated