[MS] NuGet PackageReference for C++ Projects in Visual Studio - devamazonaws.blogspot.com
Native C++ projects in Visual Studio now support
Post Updated on May 19, 2026 at 02:20AM
Thanks for reading
from devamazonaws.blogspot.com
<PackageReference>, the modern, MSBuild-native way to declare NuGet package dependencies directly in your project file. This support is available experimentally for .vcxproj projects in the Visual Studio Insiders Channel starting with version 18.7.
This feature has been the most upvoted feature request on Visual Studio Developer Community, and we're delivering it based on that feedback and in collaboration with other teams at Microsoft, including Windows and Azure.
NuGet with PackageReferences can be useful for teams that develop both .NET and C++ projects (native or interop) that need a consistent way to deploy their binaries across their repos or to their consumers, or for managing dependencies that aren't C++ libraries, such as binary SDK packages. We continue to recommend vcpkg for acquiring and managing C++ libraries, as it is more specialized and flexible for these types of dependencies.
What Is PackageReference?
Traditionally, NuGet packages in C++ projects were managed throughpackages.config, a separate XML file that listed every dependency (including transitive ones) and required a per-solution packages folder. PackageReference eliminates that by declaring dependencies directly in the project file:
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="2.0.240405.15" />
</ItemGroup>
The key advantages over packages.config:
- Single source of truth. Dependencies live in the project file alongside your other project references. No separate files required.
- Transitive dependency resolution. You only list packages you directly depend on. NuGet resolves the rest automatically at restore time.
- Global package cache. Packages are stored once on disk in a global folder, not duplicated per-solution. This means faster restores and less disk usage.
- MSBuild integration. You can use conditions to vary package references by configuration, platform, or target framework, using the same MSBuild syntax you already know.
How It Works
Once enabled, this experience is identical to .NET projects, both in the Visual Studio IDE and on the command line. There is no difference in the core UX. You can add PackageReferences by:- Editing the project file directly. Add
<PackageReference>items to an<ItemGroup>in your.vcxproj. - Using the NuGet Package Manager UI. Right-click your project in Solution Explorer, select Manage NuGet Packages, and install packages as usual.
- Using the Package Manager Console. Run
Install-Packagecommands.
How to Enable It
This feature is experimental and off by default in version 18.7. To opt in, set theEnableNativePackageReferenceSupport MSBuild property to true.
You can do this in your project file's Globals property group:
<PropertyGroup Label="Globals">
<EnableNativePackageReferenceSupport>true</EnableNativePackageReferenceSupport>
</PropertyGroup>
Or, to enable it across all projects in a repository, add it to a Directory.Build.props file:
<Project>
<PropertyGroup>
<EnableNativePackageReferenceSupport>true</EnableNativePackageReferenceSupport>
</PropertyGroup>
</Project>
Performance
We designed this feature to be fully compatible with the project load performance improvements shipped since Visual Studio 2017. One of the things holding us back from shipping PackageReference in the past was that a simpler implementation would invalidate this work, causing ongoing performance regressions for customers. Happily, this problem is now solved. The first time you add PackageReferences to a project, there is a one-time cache warm-up cost. After that initial load, the cache is warm and subsequent project operations are fully optimized with no ongoing performance impact.Current Limitations
This initial release supports native C++ projects (.vcxproj). The following scenarios are not yet supported:
- C++/CLI projects targeting legacy .NET Framework versions. (PackageReference for C++/CLI projects targeting modern .NET is already supported; see our earlier announcement.)
- C++ projects that reference C++/CLI projects or C# projects. We are investigating a solution to this. In the meantime, you can use one of these workarounds:
- Set
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>and<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>on the<ProjectReference>item, which will allow NuGet to ignore it and not cause restore and build issues. - Set
AssetTargetFallbackto include frameworks compatible with the referenced C# project. For example:<PropertyGroup> <AssetTargetFallback>net472;net10.0</AssetTargetFallback> </PropertyGroup>
- Set
What About vcpkg?
This feature does not change our recommendation for vcpkg. We continue to recommend vcpkg as the primary tool for acquiring and managing C and C++ libraries. vcpkg provides source-based builds with binary caching support, ABI compatibility management, support for offline installation, and a curated registry of thousands of open-source libraries optimized for C++ workflows. PackageReference support complements vcpkg by enabling NuGet-based distribution workflows. For example, teams that publish internal SDK packages via NuGet feeds, or projects that consume Windows-specific packages distributed through NuGet.org. The two tools serve different use cases and work well together. You can also use vcpkg to build library dependencies, then export them as NuGet with thevcpkg export --nuget command.
Try It Out
- Download Visual Studio Insiders.
- Enable the feature by setting
EnableNativePackageReferenceSupporttotruein your project orDirectory.Build.props. - Add a PackageReference to your
.vcxprojand build.
- Does the end-to-end experience work well for your projects?
- Are there gaps or rough edges you encounter?
- How does performance feel in your solutions?
Post Updated on May 19, 2026 at 02:20AM
Thanks for reading
from devamazonaws.blogspot.com
Comments
Post a Comment