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:

  1. Install this as part of your application setup/as a package manager dependency.

  2. Ask the user to manually install this.

  3. 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:

  1. Download the VisualCppRedist_AIO_x86_x64.exe file from the latest release of this GitHub repo.

  2. Use 7-Zip to extract the downloaded executable (e.g. right click, hover over 7-Zip, and click Extract to "VisualCppRedist_AIO_x86_x64\").

  3. In the extracted folder, navigate to 2022, x86 and/or x64 (depending on which platform your application targets), System or System64, and copy the vcruntime140.dll file(s) to your project folder.

  4. Add the vcruntime140.dll file(s) as embedded resources in your project.

  5. 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.

  6. 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