Skip to content

Fix NU1201 for C++/CLI project referencing native C++ project with AssetTargetFallback - #7341

Merged
nkolev92 merged 2 commits into
devfrom
fix/cppcli-native-project-reference-nu1201
May 6, 2026
Merged

nkolev92 merged 2 commits into
devfrom
fix/cppcli-native-project-reference-nu1201

Conversation

@nkolev92

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#14876

Description

When a C++/CLI project with both assetTargetFallback and secondaryFramework (DualCompatibilityFramework) references a native C++ project, restore fails with NU1201:

Project CppNative is not compatible with net10.0-windows7.0 (.NETCoreApp,Version=v10.0). Project CppNative supports: native (native,Version=v0.0)

Root Cause

In PackageSpecReferenceDependencyProvider, the framework resolution for project references had two separate type checks:

  1. is AssetTargetFallbackFramework — matched first, tried ATF imports (net461-net481) but not the secondary native framework
  2. is DualCompatibilityFramework — never reached because AssetTargetFallbackFramework does not inherit from DualCompatibilityFramework

When both ATF and DCF are combined (as they are for real C++/CLI projects), the secondary framework was lost.

Fix

Extracted a shared GetNearestTargetFrameworkWithFallbacks helper that follows the same precedence as the package path (LockFileUtils):

  1. Root framework (exact/nearest)
  2. DualCompatibilityFramework secondary (e.g., native) — before imports
  3. AssetTargetFallback imports (e.g., net472)

Applied to both GetLibrary() and GetDependenciesFromSpecRestoreMetadata() in PackageSpecReferenceDependencyProvider.

Tests Added

  • RestoreCommand_WithCPPCliProject_WithNativeProjectReference_Succeeds — C++/CLI -> native project reference (the bug repro)
  • RestoreCommand_WithCPPCliProject_WithNativeProjectReferenceWithPackageDependency_Succeeds — C++/CLI -> native project with transitive native package dependencies
  • RestoreCommand_WithNativeProject_WithCPPCliProjectReference_RaisesNU1201 — native -> C++/CLI raises NU1201 (expected behavior)

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

nkolev92 and others added 2 commits April 28, 2026 15:28
When a C++/CLI project with both assetTargetFallback and secondaryFramework
(DualCompatibilityFramework) references a native C++ project, the framework
resolution in PackageSpecReferenceDependencyProvider failed to find the native
framework. The AssetTargetFallbackFramework type check matched first, tried
only ATF imports (net461-net481), and the DualCompatibilityFramework check
was never reached since ATF does not inherit from DCF.

Extracted a shared GetNearestTargetFrameworkWithFallbacks helper that follows
the same precedence as the package path (LockFileUtils):
1. Root framework (exact/nearest)
2. DualCompatibilityFramework secondary (e.g. native)
3. AssetTargetFallback imports (e.g. net472)

Fixes NuGet/Home#14876

Co-authored-by: Copilot <[email protected]>
@nkolev92
nkolev92 marked this pull request as ready for review April 30, 2026 18:37
@nkolev92
nkolev92 requested a review from a team as a code owner April 30, 2026 18:37
@nkolev92
nkolev92 requested review from jeffkl and zivkan April 30, 2026 18:37
@nkolev92 nkolev92 changed the title Fix NU1201 for C++/CLI project referencing native C++ project with ATF Fix NU1201 for C++/CLI project referencing native C++ project with AssetTargetFallback May 5, 2026
@nkolev92
nkolev92 merged commit 67335e2 into dev May 6, 2026
17 of 18 checks passed
@nkolev92
nkolev92 deleted the fix/cppcli-native-project-reference-nu1201 branch May 6, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++/CLI PackageReference project fails when referencing a C++ PackageReference project

2 participants