Skip to content

Fix NET10_0_OR_GREATER not emitted when targeting net10.0 on MSBuild < 18 - #53976

Merged
marcpopMSFT merged 2 commits into
release/10.0.1xxfrom
copilot/update-supported-target-frameworks
Apr 22, 2026
Merged

marcpopMSFT merged 2 commits into
release/10.0.1xxfrom
copilot/update-supported-target-frameworks

Conversation

Copilot AI commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When a project targets net10.0 and is built with MSBuild < 18.0 (e.g. VS 17.14), the NET10_0_OR_GREATER preprocessor symbol is never defined. This is because SupportedNETCoreAppTargetFramework is the single source of truth used both for the VS target-framework retargeting dropdown and for NET*_OR_GREATER compiler define generation in GenerateNETCompatibleDefineConstants. The net10.0 entry in that item group is gated behind a Condition="$([MSBuild]::VersionGreaterThanOrEquals($(MSBuildVersion), '18.0.0'))", so on older tooling the item is absent and the define is never emitted.

Solution

Split the two concerns:

  1. _NETCoreAppVersionsForDefines (new) — contains all .NET Core/NET versions including net10.0, with no MSBuild version condition. Used only by GenerateNETCompatibleDefineConstants to produce NET*_OR_GREATER defines.
  2. SupportedNETCoreAppTargetFramework — now populated via Include="@(_NETCoreAppVersionsForDefines)" followed by a Remove that strips net10.0 when MSBuildVersion < 18.0.0. The VS retargeting dropdown behaviour is unchanged.

Files changed

  • src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.SupportedTargetFrameworks.props — introduce _NETCoreAppVersionsForDefines; derive SupportedNETCoreAppTargetFramework from it with conditional Remove.
  • src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets — GenerateNETCompatibleDefineConstants now reads _NETCoreAppVersionsForDefines instead of SupportedNETCoreAppTargetFramework.
  • test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs — added a net10.0 test case to It_implicitly_defines_compilation_constants_for_the_target_framework asserting that NET10_0_OR_GREATER and all preceding NET*_OR_GREATER / NETCOREAPP*_OR_GREATER defines are correctly emitted. This is a unit-level MSBuild target test (invoking AddImplicitDefineConstants directly) that does not depend on the MSBuild/VS version.

No behaviour change for

  • The VS retargeting dropdown (still hidden on VS 17.14/MSBuild 17.x).
  • The SupportedTargetFramework rollup item (built from SupportedNETCoreAppTargetFramework after the Remove).
  • All other framework identifiers (.NETFramework, .NETStandard) — untouched.
  • Future N+1 gating: add the new version to _NETCoreAppVersionsForDefines unconditionally, add a Remove in the VS-facing block with the appropriate MSBuild condition.

Tactics

Summary

When a project targets net10.0 and is built with MSBuild < 18.0 (e.g. VS 17.14), the NET10_0_OR_GREATER preprocessor symbol was never defined. The root cause was that SupportedNETCoreAppTargetFramework served dual purposes — the VS retargeting dropdown and the source for NET*_OR_GREATER compiler define generation — and its net10.0 entry was gated behind Condition="$([MSBuild]::VersionGreaterThanOrEquals($(MSBuildVersion), '18.0.0'))". This PR fixes the issue by introducing a new _NETCoreAppVersionsForDefines item group that contains all .NET versions unconditionally (used only for define generation), while SupportedNETCoreAppTargetFramework is now derived from it with a conditional Remove of net10.0 on older MSBuild. The VS retargeting dropdown behavior is fully preserved, making this a safe and surgical fix for a servicing release.

Customer Impact

Customers using the .NET 10.0 SDK while targeting net10.0 on Visual Studio 17.14 (MSBuild < 18.0) find that #if NET10_0_OR_GREATER guards never evaluate to true, causing silent behavioral differences or compilation errors depending on code structure. All developers in that version combination who rely on NET10_0_OR_GREATER or any of the cumulative NET*_OR_GREATER defines are affected. No workaround exists short of upgrading to VS 18.0 / MSBuild 18.0. The issue does not affect users on VS 18.0+ or MSBuild 18.0+. Issue #53389 was referenced by the reporter but could not be read during tactic generation.

Regression?

Yes — introduced when net10.0 was added to SupportedNETCoreAppTargetFramework with an MSBuild version gate (Condition="$([MSBuild]::VersionGreaterThanOrEquals($(MSBuildVersion), '18.0.0'))") intended to hide the framework from the VS retargeting dropdown on older VS. That condition inadvertently also suppressed compiler define generation for NET10_0_OR_GREATER on those tooling versions. The specific originating PR is not cited in the PR body, but the regression tracks to the initial introduction of the gated net10.0 entry in Microsoft.NET.SupportedTargetFrameworks.props.

Testing

  • Unit test added: A net10.0 [InlineData] entry was added to It_implicitly_defines_compilation_constants_for_the_target_framework in test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs. This test invokes the AddImplicitDefineConstants MSBuild target directly and asserts that NET10_0_OR_GREATER, all preceding NET*_OR_GREATER, and all NETCOREAPP*_OR_GREATER defines are correctly emitted — without depending on MSBuild or VS version at runtime.
  • E2E test not feasible: The CI environment uses VS 2026 / MSBuild 18+, so an integration test against MSBuild < 18.0 cannot be run in CI. The unit test approach was explicitly chosen to validate the fix path independently of tooling version.
  • CI runs on PR branch copilot/update-supported-target-frameworks.

Risk

Low. The change touches 3 files with ~30 lines changed (+27/-17). The logic is straightforward: a new unconditional item group _NETCoreAppVersionsForDefines is introduced for define generation, and SupportedNETCoreAppTargetFramework is derived from it with the same conditional Remove that was previously an inline condition. VS retargeting dropdown behavior is unchanged. All other framework identifiers (.NETFramework, .NETStandard) are untouched. A targeted unit test covers the regression scenario directly, and no behavioral changes are expected outside of the bug fix.

…net10.0

Separate the VS retargeting list (SupportedNETCoreAppTargetFramework) from
the list used for compiler define generation (_NETCoreAppVersionsForDefines).
_NETCoreAppVersionsForDefines always includes net10.0 unconditionally, so
NET10_0_OR_GREATER is emitted correctly regardless of MSBuild/VS version.
SupportedNETCoreAppTargetFramework continues to gate net10.0 behind
MSBuild 18.0.0 for the VS retargeting dropdown.

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/0bd2179c-396d-49c9-85fa-16860f6daff4

Co-authored-by: marcpopMSFT <[email protected]>
Copilot AI requested a review from marcpopMSFT April 17, 2026 18:56
@marcpopMSFT
marcpopMSFT marked this pull request as ready for review April 20, 2026 16:45
Copilot AI review requested due to automatic review settings April 20, 2026 16:45
@marcpopMSFT

Copy link
Copy Markdown
Member

/tactics

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

This PR fixes missing NET10_0_OR_GREATER compiler define emission when targeting net10.0 using MSBuild versions older than 18 by separating the framework list used for define generation from the VS retargeting list.

Changes:

  • Introduce _NETCoreAppVersionsForDefines as an unfiltered framework list for NET*_OR_GREATER define generation.
  • Derive SupportedNETCoreAppTargetFramework from _NETCoreAppVersionsForDefines, then conditionally remove net10.0 for MSBuild < 18 to preserve VS retargeting behavior.
  • Update GenerateNETCompatibleDefineConstants to read from _NETCoreAppVersionsForDefines for .NETCoreApp define generation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.SupportedTargetFrameworks.props Splits the .NETCoreApp version list into an unfiltered defines list and a VS-retargeting list with conditional removal for older MSBuild.
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets Switches NET*_OR_GREATER define generation to use the new unfiltered list.

Extend It_implicitly_defines_compilation_constants_for_the_target_framework
with a net10.0 InlineData to verify that NET10_0_OR_GREATER and all
preceding NET*_OR_GREATER defines are correctly emitted. This is a
unit-level MSBuild target test (AddImplicitDefineConstants) that does
not depend on MSBuild/VS version, so it covers the regression without
needing an E2E test against an older toolchain.

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/ba135360-e74d-449a-bd86-ac07db2c937e

Co-authored-by: marcpopMSFT <[email protected]>
Copilot AI changed the title Fix NET10_0_OR_GREATER not emitted when targeting net10.0 on MSBuild < 18 Fix NET10_0_OR_GREATER not emitted when targeting net10.0 on MSBuild &lt; 18 Apr 20, 2026
@marcpopMSFT

Copy link
Copy Markdown
Member

/tactics

@marcpopMSFT

Copy link
Copy Markdown
Member

/tactics #53389

@baronfel baronfel 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.

LGTM - thanks for splitting out the combined concepts into separate ones.

@marcpopMSFT
marcpopMSFT merged commit 6f3485e into release/10.0.1xx Apr 22, 2026
30 of 32 checks passed
@marcpopMSFT
marcpopMSFT deleted the copilot/update-supported-target-frameworks branch April 22, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants