Announcing NuGet PackageReference support for C++/CLI MSBuild projects targeting .NET Core and .NET 5 or higher

Augustin Popa

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:

<PropertyGroup Label="Globals">

<EnableManagedPackageReferenceSupport>true</EnableManagedPackageReferenceSupport> </PropertyGroup>

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 visualcpp@microsoft.com.

Posted in C++

4 comments

Discussion is closed. Login to edit/delete existing comments.

  • qbprog 0

    What a joke! You do not support c++/cli as interop story between net and cpp, in fact you are forcing everyone to migrate away from it, due to lack of support for newer standards….

  • Paulo Pinto 0

    Many thanks for updating the C++/CLI tooling, sorry for the following short rant, however it just feels outside some golden C# workflows, everything else in .NET ecosystem and CLR has kind of left to stand still.

    So, regarding ISO C++ support, when will we finally get more up to date support? It appears C++/CLI will get stuck in more or less ISO C++17.

    As for the language interoperability, now that C++/CX got replaced by the Jurassic tooling for C++/WinRT (COM and IDL VS support like in the VC++ 6.0 days), without any VS updates since 2015, C++/CLI remains the only productive way to mix C++ libraries and Win32 APIs for .NET developers.

    CsWinRT could be a better answer, but it is still too cumbersome to replace such workflows, without any Visual Studio integration and nice graphical wizards.

    There is no need for feature tickets on Developer Community, there are already plenty submitted requests.

  • Wim L 0

    Could you create a tutorial how to set up a combined C# app – C++/CLI wrapper – C++ library project?
    Using vcpkg and NuGet for dependency management.
    How do you combine CMake and MSbuild?

Feedback usabilla icon