Repository navigation
Fix NU1201 for C++/CLI project referencing native C++ project with AssetTargetFallback - #7341
Merged
Merged
Conversation
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]>
jeffkl
approved these changes
May 5, 2026
This was referenced May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: NuGet/Home#14876
Description
When a C++/CLI project with both
assetTargetFallbackandsecondaryFramework(DualCompatibilityFramework) references a native C++ project, restore fails with NU1201:Root Cause
In
PackageSpecReferenceDependencyProvider, the framework resolution for project references had two separate type checks:is AssetTargetFallbackFramework— matched first, tried ATF imports (net461-net481) but not the secondarynativeframeworkis DualCompatibilityFramework— never reached becauseAssetTargetFallbackFrameworkdoes not inherit fromDualCompatibilityFrameworkWhen both ATF and DCF are combined (as they are for real C++/CLI projects), the secondary framework was lost.
Fix
Extracted a shared
GetNearestTargetFrameworkWithFallbackshelper that follows the same precedence as the package path (LockFileUtils):native) — before importsnet472)Applied to both
GetLibrary()andGetDependenciesFromSpecRestoreMetadata()inPackageSpecReferenceDependencyProvider.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 dependenciesRestoreCommand_WithNativeProject_WithCPPCliProjectReference_RaisesNU1201— native -> C++/CLI raises NU1201 (expected behavior)PR Checklist