Repository navigation
Fix NET10_0_OR_GREATER not emitted when targeting net10.0 on MSBuild < 18 - #53976
Merged
marcpopMSFT merged 2 commits intoApr 22, 2026
Merged
Conversation
…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]>
Member
|
/tactics |
Contributor
There was a problem hiding this comment.
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
_NETCoreAppVersionsForDefinesas an unfiltered framework list forNET*_OR_GREATERdefine generation. - Derive
SupportedNETCoreAppTargetFrameworkfrom_NETCoreAppVersionsForDefines, then conditionally removenet10.0for MSBuild < 18 to preserve VS retargeting behavior. - Update
GenerateNETCompatibleDefineConstantsto read from_NETCoreAppVersionsForDefinesfor.NETCoreAppdefine 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 < 18
Apr 20, 2026
Member
|
/tactics |
Member
|
/tactics #53389 |
marcpopMSFT
approved these changes
Apr 20, 2026
baronfel
reviewed
Apr 21, 2026
baronfel
left a comment
Member
There was a problem hiding this comment.
LGTM - thanks for splitting out the combined concepts into separate ones.
baronfel
approved these changes
Apr 21, 2026
This was referenced May 10, 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.
Problem
When a project targets
net10.0and is built with MSBuild < 18.0 (e.g. VS 17.14), theNET10_0_OR_GREATERpreprocessor symbol is never defined. This is becauseSupportedNETCoreAppTargetFrameworkis the single source of truth used both for the VS target-framework retargeting dropdown and forNET*_OR_GREATERcompiler define generation inGenerateNETCompatibleDefineConstants. Thenet10.0entry in that item group is gated behind aCondition="$([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:
_NETCoreAppVersionsForDefines(new) — contains all .NET Core/NET versions includingnet10.0, with no MSBuild version condition. Used only byGenerateNETCompatibleDefineConstantsto produceNET*_OR_GREATERdefines.SupportedNETCoreAppTargetFramework— now populated viaInclude="@(_NETCoreAppVersionsForDefines)"followed by aRemovethat stripsnet10.0whenMSBuildVersion < 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; deriveSupportedNETCoreAppTargetFrameworkfrom it with conditional Remove.src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets—GenerateNETCompatibleDefineConstantsnow reads_NETCoreAppVersionsForDefinesinstead ofSupportedNETCoreAppTargetFramework.test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs— added anet10.0test case toIt_implicitly_defines_compilation_constants_for_the_target_frameworkasserting thatNET10_0_OR_GREATERand all precedingNET*_OR_GREATER/NETCOREAPP*_OR_GREATERdefines are correctly emitted. This is a unit-level MSBuild target test (invokingAddImplicitDefineConstantsdirectly) that does not depend on the MSBuild/VS version.No behaviour change for
SupportedTargetFrameworkrollup item (built fromSupportedNETCoreAppTargetFrameworkafter the Remove)..NETFramework,.NETStandard) — untouched._NETCoreAppVersionsForDefinesunconditionally, add aRemovein the VS-facing block with the appropriate MSBuild condition.Tactics
Summary
When a project targets
net10.0and is built with MSBuild < 18.0 (e.g. VS 17.14), theNET10_0_OR_GREATERpreprocessor symbol was never defined. The root cause was thatSupportedNETCoreAppTargetFrameworkserved dual purposes — the VS retargeting dropdown and the source forNET*_OR_GREATERcompiler define generation — and itsnet10.0entry was gated behindCondition="$([MSBuild]::VersionGreaterThanOrEquals($(MSBuildVersion), '18.0.0'))". This PR fixes the issue by introducing a new_NETCoreAppVersionsForDefinesitem group that contains all .NET versions unconditionally (used only for define generation), whileSupportedNETCoreAppTargetFrameworkis now derived from it with a conditionalRemoveofnet10.0on 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.0on Visual Studio 17.14 (MSBuild < 18.0) find that#if NET10_0_OR_GREATERguards never evaluate to true, causing silent behavioral differences or compilation errors depending on code structure. All developers in that version combination who rely onNET10_0_OR_GREATERor any of the cumulativeNET*_OR_GREATERdefines 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.0was added toSupportedNETCoreAppTargetFrameworkwith 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 forNET10_0_OR_GREATERon those tooling versions. The specific originating PR is not cited in the PR body, but the regression tracks to the initial introduction of the gatednet10.0entry inMicrosoft.NET.SupportedTargetFrameworks.props.Testing
net10.0[InlineData]entry was added toIt_implicitly_defines_compilation_constants_for_the_target_frameworkintest/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs. This test invokes theAddImplicitDefineConstantsMSBuild target directly and asserts thatNET10_0_OR_GREATER, all precedingNET*_OR_GREATER, and allNETCOREAPP*_OR_GREATERdefines are correctly emitted — without depending on MSBuild or VS version at runtime.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
_NETCoreAppVersionsForDefinesis introduced for define generation, andSupportedNETCoreAppTargetFrameworkis 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.