Skip to content

Place Framework buildTransitive target in the net10.0 asset group - #14469

Merged
baronfel merged 2 commits into
mainfrom
baronfel-fix-framework-transitive-targets
Jul 21, 2026
Merged

baronfel merged 2 commits into
mainfrom
baronfel-fix-framework-transitive-targets

Conversation

@baronfel

@baronfel baronfel commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #14467

Context

The Microsoft.Build.Framework package contains trim/AOT feature-switch defaults, but the target was packed at the root of buildTransitive. NuGet selected the nearer buildTransitive/net10.0/_._ compatibility placeholder for net10.0+ consumers, masking the root target.

Changes Made

Pack Microsoft.Build.Framework.targets into buildTransitive/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 supported net10.0+ consumers while preserving the existing compatibility-warning assets for older target frameworks.

Testing

  • Built and packed Microsoft.Build.Framework.
  • Confirmed the package contains:
    • buildTransitive/net10.0/Microsoft.Build.Framework.targets
    • buildTransitive/netcoreapp2.0/Microsoft.Build.Framework.targets
    • buildTransitive/net461/Microsoft.Build.Framework.targets
    • buildTransitive/net472/_._
  • Restored representative consumers and confirmed NuGet selects:
    • the net10.0 AOT target for net11.0
    • the netcoreapp2.0 compatibility target for net9.0
    • the net472 placeholder for net472

Notes

This follows the existing NuGet nearest-compatible-asset design and preserves the compatibility packaging behavior.

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
Copilot AI review requested due to automatic review settings July 20, 2026 21:40
@baronfel
baronfel requested a review from a team as a code owner July 20, 2026 21:40
@baronfel
baronfel temporarily deployed to copilot-pat-pool July 20, 2026 21:40 — with GitHub Actions Inactive
@baronfel
baronfel temporarily deployed to copilot-pat-pool July 20, 2026 21:41 — with GitHub Actions Inactive
@baronfel
baronfel temporarily deployed to copilot-pat-pool July 20, 2026 21:41 — with GitHub Actions Inactive
@baronfel
baronfel temporarily deployed to copilot-pat-pool July 20, 2026 21:47 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via InitialTargets) 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.

@baronfel
baronfel temporarily deployed to copilot-pat-pool July 20, 2026 21:49 — with GitHub Actions Inactive

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.allowed list 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

@baronfel
baronfel temporarily deployed to copilot-pat-pool July 20, 2026 21:49 — with GitHub Actions Inactive

@ViktorHofer ViktorHofer left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@baronfel

Copy link
Copy Markdown
Member Author

@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 eng/packaging.targets. I tried to pull that file's intent into the shared targets files so that we could use the correct ones in the correct places.

I suppose we could also break them apart and conditionally use one or the other in each TFM-specific subfolder?

@ViktorHofer

Copy link
Copy Markdown
Member

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
@baronfel baronfel changed the title Fix Microsoft.Build.Framework buildTransitive target packaging Place Framework buildTransitive target in the net10.0 asset group Jul 21, 2026
@baronfel

Copy link
Copy Markdown
Member Author

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.

@baronfel

Copy link
Copy Markdown
Member Author

Thanks for the guidance - after sleeping on it and looking at the generated targets of course you're right :)

@baronfel

Copy link
Copy Markdown
Member Author

Addressed the automated review against the superseded implementation: the added test was removed, compatibility warning generation and InitialTargets behavior are unchanged, eng/packaging.targets is restored, and the current net diff is only the buildTransitive\net10.0 PackagePath change. The PR description and validation results now reflect that final implementation.

@baronfel
baronfel dismissed github-actions[bot]’s stale review July 21, 2026 15:35

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.

@baronfel
baronfel merged commit 3c5a18d into main Jul 21, 2026
10 checks passed
@baronfel
baronfel deleted the baronfel-fix-framework-transitive-targets branch July 21, 2026 15:50
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.

Microsoft.Build.Framework buildTransitive AOT feature-switch targets are masked by TFM-specific _._

3 participants