NuGet for C++
The wait is over. NuGet support for C++ projects is here.
• NuGet 2.5 Download page: https://nuget.codeplex.com/releases/view/96733
• CoApp’s Powershell Tools Installer to create C++ NuGet packages: http://coapp.org/releases
• Some C++ NuGet packages to try out: http://nuget.org/profiles/coapp/
Start downloading, then head on back here to learn more about NuGet and how to create and use packages for C++ libraries.
What is NuGet?
From the NuGet website:
NuGet is a Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects… If you develop a library or tool that you want to share with other developers, you create a NuGet package and store the package in a NuGet repository. If you want to use a library or tool that someone else has developed, you retrieve the package from the repository and install it in your Visual Studio project or solution.
With the NuGet 2.5 release, you can download and add libraries to your C++ projects without having to configure properties for include or library directories, and making sure those properties are set correctly in all of your project configurations. For C++, the way we implement this is by generating files with MSBuild properties and targets, and including those files in the NuGet package. When the package is installed and referenced by your project, the MSBuild files are imported into your project file, so your projects will know how to find and use the contents of the NuGet packages. Packages are cached on a per-solution basis – if you’re using the same library in multiple projects in your solution, they’ll point to a common copy of the package.
Check out this post on the NuGet team blog for a more in-depth look at how NuGet for C++ was designed.
NuGet is included in both Visual Studio 2010 and Visual Studio 2012. You’ll need to update the NuGet extension to version 2.5 in order to use the C++ project integration. The NuGet website (nuget.org) has extensive documentation on how to install and use NuGet. You can use NuGet in any C++ project type – this works for desktop, Windows Store, and Windows Phone 8 applications equally.
The NuGet Gallery on nuget.org is the central package repository used by all package authors and consumers. Since C++ support in NuGet is brand new, there aren’t a lot of packages available in the NuGet Gallery yet. However, the CoApp project has created a few packages from open source libraries which you can use right now to get started. You can find their packages on the NuGet gallery here. To find other packages, try using a search on “tag:native” on the NuGet Gallery (this also works when searching for packages using the VS IDE integration), though be aware that not all packages tagged with “native” are actually C++ projects.
If you’re interested in publishing your libraries via NuGet, you can choose to create the NuGet packages manually. However, there’s an easier way. The CoApp project volunteered to write C++ oriented tools to create NuGet packages, and have released a beta version of their tools on their website. These tools simplify the process of generating the MSBuild files and NuGet packages from existing header and library files – you just need to create a configuration script to describe the contents of the package, and then run the tools to generate the NuGet package.
There are tutorials, reference documentation, and a video on how to use the tools to create NuGet packages. The CoApp project organizers also plan to create and publish packages for several open source libraries into the NuGet Gallery over the next several weeks.
At this time, we’re encouraging people to publish packages with the “native” tag to make it easier to find packages you can use in C++ projects.
Please leave us feedback here on the blog – we’d love to hear your experiences trying out NuGet in your C++ projects, and whether there are additional features we could add to make this work even better for you. This is just the start of C++ integration in NuGet – we need your input on where we should take this in the future to make working with C++ libraries in Visual Studio easier.