Getting libsodium to work on Windows

libsodium requires the Visual C++ Redistributable for Visual Studio 2015-2022arrow-up-right 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 dependencyarrow-up-right.

  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-containedarrow-up-right), 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 releasearrow-up-right of thisarrow-up-right GitHub repo.

  2. Use 7-Ziparrow-up-right 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 resourcesarrow-up-right in your project.

  5. Write some code that extracts the relevant (x86 or x64) file to the location of your executablearrow-up-right or to the directory where the libsodium.dll file is locatedarrow-up-right 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 Sandboxarrow-up-right or a virtual machinearrow-up-right).

Last updated