One of the new features for C++ developers in Visual Studio 2022 version 17.3 is NuGet PackageReference support for C++/CLI MSBuild projects that target .NET Core and .NET 5 or higher. More specifically, this impacts CLR Class Library (.NET) and CLR Empty Project (.NET) project templates. This functionality allows you to manage NuGet packages while bringing the benefits of PackageReference support to your dependencies. This feature is on by default for new projects. To enable this feature for your existing projects, add the following property to your project file:
In most cases, you will want to enable this for the whole codebase. You can do this by setting the property in a Directory.Build.props file instead.
When this property is set to true, NuGet will recognize on project load that the project is participating in the PackageReference experience and begin restoring packages just as it would for a .NET project.
Note: in order to modify this setting in any way, it is required to unload the project file, make the change, then reload it for the change to take effect. This setting cannot be changed for an actively loaded project.
Is PackageReference support limited to managed C++/CLI projects?
In short, yes. It is important to support NuGet PackageReference for projects that touch .NET code since NuGet is the recommended dependency management solution for .NET. Furthermore, the C++ team will continue supporting C++/CLI projects as an interop story between C++ and .NET.
For native C++ projects, we recommend using vcpkg for both C++ open-source and closed source libraries. With compilation from source, binary caching, custom registries, version conflict resolution, and more, we believe this will provide the best experience for managing C/C++ dependencies. vcpkg can also target a large variety of platforms and architectures natively and works with any C++ build system.
With that said, we would love to hear your feedback on language interop scenarios with C++: please file suggestion tickets on Developer Community.
Give us your feedback
We would love to hear from you! Download Visual Studio 2022, give it a try, and file bugs or feature requests on Visual Studio Developer Community. For new issues within NuGet, please report a GitHub Issue. For general NuGet experience issues, let us know via the Report a Problem option in Visual Studio found under the Help > Report A Problem menu.
Feel free to leave comments in this blog post with your thoughts or reach out to us at [email protected].