{"id":36522,"date":"2026-05-19T01:20:44","date_gmt":"2026-05-19T01:20:44","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=36522"},"modified":"2026-05-19T01:20:44","modified_gmt":"2026-05-19T01:20:44","slug":"nuget-packagereference-for-c-projects-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/nuget-packagereference-for-c-projects-in-visual-studio\/","title":{"rendered":"NuGet PackageReference for C++ Projects in Visual Studio"},"content":{"rendered":"<p>Native C++ projects in Visual Studio now support <code>&lt;PackageReference&gt;<\/code>, the modern, MSBuild-native way to declare NuGet package dependencies directly in your project file. This support is available experimentally for <code>.vcxproj<\/code> projects in the Visual Studio Insiders Channel starting with version 18.7.<\/p>\n<p>This feature has been the <a href=\"https:\/\/developercommunity.visualstudio.com\/t\/use-packagereference-in-vcxproj\/351636\">most upvoted feature request<\/a> on Visual Studio Developer Community, and we&#8217;re delivering it based on that feedback and in collaboration with other teams at Microsoft, including Windows and Azure.<\/p>\n<p>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&#8217;t C++ libraries, such as binary SDK packages. We continue to recommend <a href=\"https:\/\/vcpkg.io\/en\/\">vcpkg<\/a> for acquiring and managing C++ libraries, as it is more specialized and flexible for these types of dependencies.<\/p>\n<h2>What Is PackageReference?<\/h2>\n<p>Traditionally, NuGet packages in C++ projects were managed through <code>packages.config<\/code>, a separate XML file that listed every dependency (including transitive ones) and required a per-solution <code>packages<\/code> folder. PackageReference eliminates that by declaring dependencies directly in the project file:<\/p>\n<pre><code class=\"language-xml\">&lt;ItemGroup&gt;\r\n  &lt;PackageReference Include=\"Microsoft.Windows.CppWinRT\" Version=\"2.0.240405.15\" \/&gt;\r\n&lt;\/ItemGroup&gt;<\/code><\/pre>\n<p>The key advantages over <code>packages.config<\/code>:<\/p>\n<ul>\n<li><strong>Single source of truth.<\/strong> Dependencies live in the project file alongside your other project references. No separate files required.<\/li>\n<li><strong>Transitive dependency resolution.<\/strong> You only list packages you directly depend on. NuGet resolves the rest automatically at restore time.<\/li>\n<li><strong>Global package cache.<\/strong> Packages are stored once on disk in a global folder, not duplicated per-solution. This means faster restores and less disk usage.<\/li>\n<li><strong>MSBuild integration.<\/strong> You can use conditions to vary package references by configuration, platform, or target framework, using the same MSBuild syntax you already know.<\/li>\n<\/ul>\n<p>For a full overview, see the <a href=\"https:\/\/learn.microsoft.com\/nuget\/consume-packages\/package-references-in-project-files\">PackageReference documentation<\/a> on Microsoft Learn. If you&#8217;re migrating an existing project, see <a href=\"https:\/\/learn.microsoft.com\/nuget\/consume-packages\/migrate-packages-config-to-package-reference\">Migrate from packages.config to PackageReference<\/a>.<\/p>\n<h2>How It Works<\/h2>\n<p>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:<\/p>\n<ol>\n<li><strong>Editing the project file directly.<\/strong> Add <code>&lt;PackageReference&gt;<\/code> items to an <code>&lt;ItemGroup&gt;<\/code> in your <code>.vcxproj<\/code>.<\/li>\n<li><strong>Using the NuGet Package Manager UI.<\/strong> Right-click your project in Solution Explorer, select <strong>Manage NuGet Packages<\/strong>, and install packages as usual.<\/li>\n<li><strong>Using the Package Manager Console.<\/strong> Run <code>Install-Package<\/code> commands.<\/li>\n<\/ol>\n<p>NuGet restore handles downloading, caching, and making package assets available to your build. The underlying implementation uses core CPS (Common Project System) capabilities, the same infrastructure that powers this feature for .NET projects.<\/p>\n<h2>How to Enable It<\/h2>\n<p>This feature is experimental and off by default in version 18.7. To opt in, set the <code>EnableNativePackageReferenceSupport<\/code> MSBuild property to <code>true<\/code>.<\/p>\n<p>You can do this in your project file&#8217;s <code>Globals<\/code> property group:<\/p>\n<pre><code class=\"language-xml\">&lt;PropertyGroup Label=\"Globals\"&gt;\r\n  &lt;EnableNativePackageReferenceSupport&gt;true&lt;\/EnableNativePackageReferenceSupport&gt;\r\n&lt;\/PropertyGroup&gt;<\/code><\/pre>\n<p>Or, to enable it across all projects in a repository, add it to a <code>Directory.Build.props<\/code> file:<\/p>\n<pre><code class=\"language-xml\">&lt;Project&gt;\r\n  &lt;PropertyGroup&gt;\r\n    &lt;EnableNativePackageReferenceSupport&gt;true&lt;\/EnableNativePackageReferenceSupport&gt;\r\n  &lt;\/PropertyGroup&gt;\r\n&lt;\/Project&gt;<\/code><\/pre>\n<h2>Performance<\/h2>\n<p>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.<\/p>\n<h2>Current Limitations<\/h2>\n<p>This initial release supports native C++ projects (<code>.vcxproj<\/code>). The following scenarios are not yet supported:<\/p>\n<ul>\n<li>C++\/CLI projects targeting legacy .NET Framework versions. (PackageReference for C++\/CLI projects targeting modern .NET is already supported; see our <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/announcing-nuget-packagereference-support-for-c-cli-msbuild-projects-targeting-net-core\/\">earlier announcement<\/a>.)<\/li>\n<li>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:\n<ul>\n<li>Set <code>&lt;ReferenceOutputAssembly&gt;false&lt;\/ReferenceOutputAssembly&gt;<\/code> and <code>&lt;SkipGetTargetFrameworkProperties&gt;true&lt;\/SkipGetTargetFrameworkProperties&gt;<\/code> on the <code>&lt;ProjectReference&gt;<\/code> item, which will allow NuGet to ignore it and not cause restore and build issues.<\/li>\n<li>Set <code>AssetTargetFallback<\/code> to include frameworks compatible with the referenced C# project. For example:\n<pre><code class=\"language-xml\">&lt;PropertyGroup&gt;\r\n&lt;AssetTargetFallback&gt;net472;net10.0&lt;\/AssetTargetFallback&gt;\r\n&lt;\/PropertyGroup&gt;<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>What About vcpkg?<\/h2>\n<p>This feature does not change our recommendation for <a href=\"https:\/\/vcpkg.io\/en\/\">vcpkg<\/a>. We continue to recommend <a href=\"https:\/\/vcpkg.io\">vcpkg<\/a> 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.<\/p>\n<p>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 the <a href=\"https:\/\/learn.microsoft.com\/vcpkg\/commands\/export#nuget\"><code>vcpkg export --nuget<\/code><\/a> command.<\/p>\n<h2>Try It Out<\/h2>\n<ol>\n<li><strong>Download <a href=\"https:\/\/visualstudio.microsoft.com\/insiders\/\">Visual Studio Insiders<\/a>.<\/strong><\/li>\n<li><strong>Enable the feature<\/strong> by setting <code>EnableNativePackageReferenceSupport<\/code> to <code>true<\/code> in your project or <code>Directory.Build.props<\/code>.<\/li>\n<li><strong>Add a PackageReference<\/strong> to your <code>.vcxproj<\/code> and build.<\/li>\n<\/ol>\n<p>We want your feedback. This is an experimental release, and your input will directly shape how we evolve this feature before enabling it by default. Let us know:<\/p>\n<ul>\n<li>Does the end-to-end experience work well for your projects?<\/li>\n<li>Are there gaps or rough edges you encounter?<\/li>\n<li>How does performance feel in your solutions?<\/li>\n<\/ul>\n<p>You can share feedback through <a href=\"https:\/\/developercommunity.visualstudio.com\/\">Developer Community<\/a>, the blog comments below, or <strong>Help \u2192 Send Feedback<\/strong> in Visual Studio.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Native C++ projects (.vcxproj) now support NuGet PackageReference, the same modern package management experience .NET developers have used for years. Available as an experimental feature in Visual Studio 2026 version 18.7.<\/p>\n","protected":false},"author":1063,"featured_media":35743,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[270,1,3958],"tags":[191,185],"class_list":["post-36522","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement","category-cplusplus","category-visual-studio","tag-nuget","tag-visual-studio"],"acf":[],"blog_post_summary":"<p>Native C++ projects (.vcxproj) now support NuGet PackageReference, the same modern package management experience .NET developers have used for years. Available as an experimental feature in Visual Studio 2026 version 18.7.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/36522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/1063"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=36522"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/36522\/revisions"}],"predecessor-version":[{"id":36525,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/36522\/revisions\/36525"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35743"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=36522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=36522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=36522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}