Please release this library as a NuGet package.
Feel free to make a proposal. Nearly all supported package manager support were provided by the community via pull requests.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I have created a NuGet package for single-header distribution and added it to the default NuGet source (nuget.org). The scripts that generates this package can be found at https://github.com/hnkb/nlohmann-json-nuget/. I'll try to keep the NuGet packages up-to-date after each new release.
Very nice! Can you provide some example code how to install the library and compile a simple program? I never used NuGet myself, but it would be good to know.
Probably the easiest way to use NuGet packages is through Visual Studio graphical interface. Just right-click on a project (any C++ project would do) in “Solution Explorer” and select “Manage NuGet Packages…”

Now you can click on “Browse” tab and find the package you like to install.

Most of the packages in NuGet gallery are .NET packages and would not be useful in a C++ project. Microsoft recommends adding _“native”_ and _“nativepackage”_ tags to C++ NuGet packages to distinguish them, but even adding “native” to search query would still show many .NET-only packages in the list.
Nevertheless, after finding the package you want, just click on “Install” button and accept confirmation dialogs. After the package is successfully added to the projects, you should be able to just build and execute the project without the need for making any more changes to build settings.
A few notes:
After you add a NuGet package, three changes occur in the project source directory. Of course, we could make these changes manually instead of using GUI:

A packages.config file will be created (or updated to include the package name if one such file already exists). This file contains a list of the packages required by this project (name and minimum version) and _must be added to the project source code repository_, so if you move the source code to a new machine, MSBuild/NuGet knows which packages it has to restore (which it does automatically before each build).
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nlohmann.json" version="3.5.0" targetFramework="native" />
</packages>
A packages folder which contains actual files in the packages (these are header and binary files required for a successful build, plus a few metadata files). In case of this library for example, it contains json.hpp:

_This directory should not be added to the project source code repository_, as it will be restored before each build by MSBuild/NuGet. If you go ahead and delete this folder, then build the project again, it will magically re-appear!
Project MSBuild makefile (which for Visual C++ projects has a .vcxproj extension) will be updated to include settings from the package.

The important bit for us here is line 170, which tells MSBuild to import settings from packages\nlohmann.json.3.5.0\build\native\nlohmann.json.targets file. This is a file the package creator created and added to the package (you can see it is one of the two files I created in this repository, the other just contains package attributes like name and version number). What does it contain?
For our header-only repository, the only setting we need is to add our include directory to the list of AdditionalIncludeDirectories:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
</Project>
For libraries with binary files, we will need to add .lib files to linker inputs, and add settings to copy .dll and other redistributable files to output directory, if needed.
There are other changes to the makefile as well:
Lines 165-167 add the packages.config as one of project files (so it is shown in Solution Explorer tree view). It is added as None (no build action) and removing it wouldn’t affect build.
Lines 172-177 check to ensure the required packages are present. This will display a build error if package directory is empty (for example when NuGet cannot restore packages because Internet connection is down). Again, if you omit this section, the only change in build would be a more cryptic error message if build fails.
_Changes to .vcxproj makefile should also be added to project source code repository._
As you can see, the mechanism NuGet uses to modify project settings is through MSBuild makefiles, so using NuGet with other build systems and compilers (like CMake) as a dependency manager is either impossible or more problematic than useful.
There is a nuget.exe command line utility which can pack files into a NuGet package (which is a zip file with a certain structure, usually with a .nupkg extension) . After this file is created, we can upload it to a package source, like http://nuget.org/, which is the default location Visual Studio uses; but you can also create local package sources, e.g. if your company does not want to share its packages with outside.
To create a package, we need:
Then call nuget.exe, passing name of the .nuspec file and the package will be created. This can be added as a build step too, if needed.
Thanks for the extensive documentation!!! I shall add a note to the README and link this issue for further information. I shall take your walk-through with the screenshots to the overworked documentation once it is done.
Most helpful comment
Probably the easiest way to use NuGet packages is through Visual Studio graphical interface. Just right-click on a project (any C++ project would do) in “Solution Explorer” and select “Manage NuGet Packages…”
Now you can click on “Browse” tab and find the package you like to install.
Most of the packages in NuGet gallery are .NET packages and would not be useful in a C++ project. Microsoft recommends adding _“native”_ and _“nativepackage”_ tags to C++ NuGet packages to distinguish them, but even adding “native” to search query would still show many .NET-only packages in the list.
Nevertheless, after finding the package you want, just click on “Install” button and accept confirmation dialogs. After the package is successfully added to the projects, you should be able to just build and execute the project without the need for making any more changes to build settings.
A few notes:
What happens behind the scenes
After you add a NuGet package, three changes occur in the project source directory. Of course, we could make these changes manually instead of using GUI:
A packages.config file will be created (or updated to include the package name if one such file already exists). This file contains a list of the packages required by this project (name and minimum version) and _must be added to the project source code repository_, so if you move the source code to a new machine, MSBuild/NuGet knows which packages it has to restore (which it does automatically before each build).
A packages folder which contains actual files in the packages (these are header and binary files required for a successful build, plus a few metadata files). In case of this library for example, it contains json.hpp:
_This directory should not be added to the project source code repository_, as it will be restored before each build by MSBuild/NuGet. If you go ahead and delete this folder, then build the project again, it will magically re-appear!
Project MSBuild makefile (which for Visual C++ projects has a .vcxproj extension) will be updated to include settings from the package.
The important bit for us here is line 170, which tells MSBuild to import settings from packages\nlohmann.json.3.5.0\build\native\nlohmann.json.targets file. This is a file the package creator created and added to the package (you can see it is one of the two files I created in this repository, the other just contains package attributes like name and version number). What does it contain?
For our header-only repository, the only setting we need is to add our include directory to the list of AdditionalIncludeDirectories:
For libraries with binary files, we will need to add .lib files to linker inputs, and add settings to copy .dll and other redistributable files to output directory, if needed.
There are other changes to the makefile as well:
Lines 165-167 add the packages.config as one of project files (so it is shown in Solution Explorer tree view). It is added as None (no build action) and removing it wouldn’t affect build.
Lines 172-177 check to ensure the required packages are present. This will display a build error if package directory is empty (for example when NuGet cannot restore packages because Internet connection is down). Again, if you omit this section, the only change in build would be a more cryptic error message if build fails.
_Changes to .vcxproj makefile should also be added to project source code repository._
As you can see, the mechanism NuGet uses to modify project settings is through MSBuild makefiles, so using NuGet with other build systems and compilers (like CMake) as a dependency manager is either impossible or more problematic than useful.
How to create a NuGet package
There is a nuget.exe command line utility which can pack files into a NuGet package (which is a zip file with a certain structure, usually with a .nupkg extension) . After this file is created, we can upload it to a package source, like http://nuget.org/, which is the default location Visual Studio uses; but you can also create local package sources, e.g. if your company does not want to share its packages with outside.
To create a package, we need:
Then call nuget.exe, passing name of the .nuspec file and the package will be created. This can be added as a build step too, if needed.