Skip to content

Handle missing TargetFramework in nomination - #7192

Merged
nkolev92 merged 3 commits into
release/7.5.xfrom
dev-nkolev92-handleMissingTargetFramework
Mar 6, 2026
Merged

nkolev92 merged 3 commits into
release/7.5.xfrom
dev-nkolev92-handleMissingTargetFramework

Conversation

@nkolev92

@nkolev92 nkolev92 commented Mar 5, 2026 •

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#14788

Description

When we changed the main parts of restore to use TargetAlias as the pivot instead of the NuGetFramework it basically meant that TargetAlias needs to either be empty or have a value.

In many places in restore we default to empty if there's no value (non SDK projects)

https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs#L445

https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks.Console/MSBuildStaticGraphRestore.cs#L734

In legacy PR, we don't set it.

In CPSPackageReference projects however, we set it, expecting that it's only invoked in SDK based scenarios but unfortunately that's not the case.

Enter C++/CLI PackageReference hacks!

The confirmed scenario in question seems to be C++/CLI PackageReference (.NET Framework projects).

C++/CLI (.NET Core) supports PackageReference projects: https://devblogs.microsoft.com/cppblog/announcing-nuget-packagereference-support-for-c-cli-msbuild-projects-targeting-net-core/ . The way that works is the C++/CPS/project-system teams worked so that the nomination code from the managed lang system is being utilized to provide this restore data to NuGet. In the end for NuGet, while we did add some special compatibility rules, these restores appear the same as a normal SDK based project.

Note that native C++ PackageReference is not supported, https://developercommunity.visualstudio.com/t/Add-PackageReference-support-for-native-/10165376 . Similarly to many scenarios, it can work on the commandline, but project reference protocol and VS scenarios just won't work. Customers haven't really cared about that limitation.
They have been using all kinds of workarounds: Use PackageReference in vcxproj - Developer Community NuGet/Home#8874 .

They basically set things like Capability, and all kinds of stuff to try to work around the implementation limiting when restore works.
These things are all unsupported. We have been clear about that, since not all scenarios are handled in C++ PackageReference today.
NuGet generates assets file, nuget.g.props, nuget.g.targets and none of those are guaranteed to be loaded or refreshed in these scenarios. So restore happens, but whether the build or intellisense actually works the way they wanted is not guaranteed.

That being said, this did get broken and the fix is rather straightforward, so we'll fix it, but we won't service stable, but insiders only.

There is a workaround and that is setting the TargetFramework value.

sample nomination data for a C++/CLI project, https://github.com/jwfx/NuGetRestoreRepro/blob/master/Directory.Build.props.

BEGIN Nominate Restore for E:\Code\Temp\NuGetRestoreRepro\NuGetRestoreRepro\NuGetRestoreRepro.vcxproj
    MSBuildProjectExtensionsPath:     E:\Code\Temp\NuGetRestoreRepro\NuGetRestoreRepro\obj\
    OriginalTargetFrameworks:         
    Target Frameworks (1)
        native,Version=v0.0
            Framework References
            Package Downloads
            Project References
            Package References
                Newtonsoft.Json -- (Aliases: | ExcludeAssets: | GeneratePathProperty: | IncludeAssets: | IsImplicitlyDefined: | Name: | NoWarn: | PrivateAssets: | Version:13.0.4 | VersionOverride: | Visible:)
            NuGet Audit Suppressions
            Prune Package References
            Package Versions -- 0 (count only)
            Target Framework Properties -- (RestoreLockedMode: | RestorePackagesWithLockFile: | NuGetAudit:true | RestoreEnablePackagePruning:false | RestoreAdditionalProjectFallbackFolders: | TargetPlatformIdentifier:Windows | RestorePackagesPath: | MSBuildProjectDirectory:E:\Code\Temp\NuGetRestoreRepro\NuGetRestoreRepro | RestoreAdditionalProjectSources: | CentralPackageFloatingVersionsEnabled: | PackageId: | RuntimeIdentifier: | NoWarn:;NU1701;NU1702 | RestoreAdditionalProjectFallbackFoldersExcludes: | TargetFrameworkIdentifier:.NETFramework | VersionSuffix: | DotnetCliToolTargetFramework: | CLRSupport:true | VersionPrefix: | TargetPlatformVersion:10.0.26100.0 | Version:1.0.0.0 | NuGetAuditMode:direct | CentralPackageVersionOverrideEnabled: | NETCoreSdkVersion: | RestoreFallbackFolders: | MSBuildProjectFile:NuGetRestoreRepro.vcxproj | NuGetAuditLevel:low | TargetFrameworkMoniker:.NETFramework,Version=v4.8 | WarningsNotAsErrors: | TargetPlatformMoniker:Windows,Version=10.0.26100.0 | TargetPlatformMinVersion:7.0 | EmitAssetsLogMessages: | RestorePackagePruningDefault:false | TargetFramework:native | UsingMicrosoftNETSdk: | PackageTargetFallback: | ProjectAssetsFile:E:\Code\Temp\NuGetRestoreRepro\NuGetRestoreRepro\obj\project.assets.json | RestoreUseLegacyDependencyResolver: | WindowsTargetPlatformMinVersion:7.0 | ManagePackageVersionsCentrally: | TreatWarningsAsErrors: | TargetFrameworkProfile: | RestoreSources: | TargetFrameworks: | NuGetTargetMoniker:native,Version=v0.0 | RuntimeIdentifierGraphPath: | MSBuildProjectExtensionsPath:E:\Code\Temp\NuGetRestoreRepro\NuGetRestoreRepro\obj\ | TargetFrameworkVersion:v4.8 | NuGetLockFilePath: | RuntimeIdentifiers:win;win-x86;win-x64;win-arm64 | PackageVersion: | SdkAnalysisLevel: | CentralPackageTransitivePinningEnabled: | WarningsAsErrors: | AssetTargetFallback:net48)
    Tool References

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
nkolev92 marked this pull request as ready for review March 6, 2026 00:47
@nkolev92
nkolev92 requested a review from a team as a code owner March 6, 2026 00:47
@nkolev92
nkolev92 requested review from jeffkl and martinrrm March 6, 2026 00:47
@nkolev92 nkolev92 changed the title Handle missing TargetFramework Handle missing TargetFramework in nomination Mar 6, 2026
@nkolev92
nkolev92 merged commit 4cc102a into release/7.5.x Mar 6, 2026
16 checks passed
@nkolev92
nkolev92 deleted the dev-nkolev92-handleMissingTargetFramework branch March 6, 2026 19:24
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.

3 participants