Repository navigation
Place Framework buildTransitive target in the net10.0 asset group - #14469
Conversation
Move the package-family TFM support warning into the root Framework buildTransitive target so NuGet does not mask the AOT feature switches with TFM-specific placeholders. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 03420b80-4177-420b-952d-9befae236b34
There was a problem hiding this comment.
Pull request overview
Fixes the Microsoft.Build.Framework NuGet package’s buildTransitive asset layout so the trim/AOT feature-switch target can’t be masked by TFM-specific _._ placeholders. This ensures trimmed and Native AOT consumers reliably import Microsoft.Build.Framework.targets via NuGet-generated imports and receive the intended default RuntimeHostConfigurationOption feature switches.
Changes:
- Consolidates the TFM support warning into the root
buildTransitive/Microsoft.Build.Framework.targets(and runs it viaInitialTargets) so it’s always imported when the target is imported. - Removes the repo-wide packaging plumbing that generated TFM-specific compatibility-warning targets and supported-TFM
_._placeholders. - Adds unit-test coverage validating (1) supported/unsupported TFM warning behavior + suppression and (2) trim/AOT default feature-switch properties/items.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/MSBuild/MSBuild.csproj | Removes a packaging-only property that’s no longer used after deleting the compatibility-warning packaging plumbing. |
| src/Framework/buildTransitive/Microsoft.Build.Framework.targets | Moves the support warning into the single root target file and ensures it runs early; keeps trim/AOT feature-switch defaults in the same unified file. |
| src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj | Adds the framework buildTransitive targets file as a copied test asset for regression coverage. |
| src/Build.UnitTests/FrameworkPackageTargets_Tests.cs | New regression tests for warning/suppression behavior and trim/AOT default feature-switch propagation. |
| eng/packaging.targets | Deletes the shared target that generated TFM-specific compatibility-warning targets and _._ placeholders. |
| Directory.Build.targets | Removes the pack-time import of eng/packaging.targets now that the packaging behavior is no longer used. |
There was a problem hiding this comment.
Review Summary
Requesting changes due to one likely bug and one breaking-change concern.
🐛 Bug: Property name mismatch in test (High)
FrameworkPackageTargets_Tests.TrimmedPublishReceivesFeatureSwitchDefaults asserts MicrosoftBuildEnableRestrictPropertyFunctionReceivers but the targets file defines MicrosoftBuildRestrictPropertyFunctionReceivers. The ShouldBe("true") assertion should fail — either the test isn't running or there's a copy-paste error.
⚠️ Breaking change: New warning for package consumers (High)
The <Warning> in InitialTargets fires at consumer build time for anyone on < net10.0 / < net472. With /WarnAsError this breaks builds. The old packaging.targets generated this at pack-time (author-side); the new behavior fires at consumer-side. This needs a ChangeWave or a suppressible warning code.
i️ netstandard2.0 gap (Low)
netstandard2.0 consumers get no warning because TargetFrameworkIdentifier is .NETStandard — not matched by either condition. This may be intentional (netstandard is a contract, not a runtime) but differs from the old behavior which warned netstandard consumers. Worth a comment in the targets file clarifying intent.
i️ Removal of eng/packaging.targets
Confirm no other IsPackable projects in the repo relied on the NETStandardCompatError items or the AddNETStandardCompatErrorFileForPackaging target for their own packages.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpg
To allow these domains, add them to the
network.allowedlist in your workflow frontmatter:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
Generated by Expert Code Review (on open) for #14469 · 65 AIC · ⌖ 5.36 AIC · ⊞ 5K
There was a problem hiding this comment.
Kudos for finding the issue.
We prefer NuGet to pick the right asset over doing conditional selection based on TFM. NuGet asset selection picks the nearest compatible asset. Right now there's a netcoreapp2.0 folder (with the NETStandardCompat target), an empty net10.0 folder and the targets file outside of a TFM folder. Due to that, NuGet picks the placeholder file inside the net10.0 folder and does nothing. It ignores the other two files as they aren't nearest matching assets.
To fix this issue, I would really only do a one line change here. Change the PackagePath metadata to buildTransitive\net10.0\Microsoft.Build.Framework.targets.
The placeholder target is smart enough to only emit a placeholder file when the folder is empty (here).
With that, the AOT targets file is selected as nearest when targeting >= net10.0. I assume that's the intention.
|
@ViktorHofer the problem with that is we have separate targets that get generated during build time for purposes of yelling at folks that use the MSBuild libraries on incorrect TFMs, so the targets that are directly in the repo get conditionally excluded/manipulated by the contents of I suppose we could also break them apart and conditionally use one or the other in each TFM-specific subfolder? |
|
I'm aware of that - I implemented the NETStandard compact target generation in this repo and runtime. The target that Jeremy added should only be required when targeting a supported NETCoreApp version (>= net10.0). Therefore, my above recommendation. |
Restore the existing compatibility-target packaging and place the Framework trim/AOT target in the net10.0 buildTransitive asset group so NuGet selects it for supported consumers. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 03420b80-4177-420b-952d-9befae236b34
|
Thanks @ViktorHofer — updated the PR to follow your recommendation. The net diff is now the single PackagePath change to buildTransitive\net10.0. I also repacked and restored net11.0, net9.0, and net472 consumers to verify NuGet selects the expected AOT target, compatibility target, and placeholder respectively. |
|
Thanks for the guidance - after sleeping on it and looking at the generated targets of course you're right :) |
|
Addressed the automated review against the superseded implementation: the added test was removed, compatibility warning generation and |
This review applies to a superseded implementation. The PR was rewritten to the approved one-line PackagePath change; the added test, warning, InitialTargets change, and packaging removal were all reverted.
Fixes #14467
Context
The
Microsoft.Build.Frameworkpackage contains trim/AOT feature-switch defaults, but the target was packed at the root ofbuildTransitive. NuGet selected the nearerbuildTransitive/net10.0/_._compatibility placeholder fornet10.0+consumers, masking the root target.Changes Made
Pack
Microsoft.Build.Framework.targetsintobuildTransitive/net10.0. The existing compatibility packaging detects that the folder is no longer empty and does not add_._, allowing NuGet to select the AOT target for supportednet10.0+consumers while preserving the existing compatibility-warning assets for older target frameworks.Testing
Microsoft.Build.Framework.buildTransitive/net10.0/Microsoft.Build.Framework.targetsbuildTransitive/netcoreapp2.0/Microsoft.Build.Framework.targetsbuildTransitive/net461/Microsoft.Build.Framework.targetsbuildTransitive/net472/_._net10.0AOT target fornet11.0netcoreapp2.0compatibility target fornet9.0net472placeholder fornet472Notes
This follows the existing NuGet nearest-compatible-asset design and preserves the compatibility packaging behavior.