Skip to content

Remove NET9_0_OR_GREATER and NET10_0_OR_GREATER preprocessor constants#122953

Merged
stephentoub merged 9 commits into
mainfrom
copilot/update-compilation-constants
Jan 7, 2026
Merged

Remove NET9_0_OR_GREATER and NET10_0_OR_GREATER preprocessor constants#122953
stephentoub merged 9 commits into
mainfrom
copilot/update-compilation-constants

Conversation

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

Cleanup of .NET Version Constants

The repo no longer builds for .NET Core versions older than 10. This PR removes obsolete version-specific preprocessor constants (NET9_0_OR_GREATER, NET10_0_OR_GREATER).

Strategy

For files that only build for .NET 10+ runtime (System.Private.CoreLib):

  • Replace #if NET9_0_OR_GREATER / #if NET10_0_OR_GREATER with #if NET
  • This is needed because these files are also compiled by packages like Microsoft.Bcl.AsyncInterfaces which target netstandard/netframework

For files in netcore directories or ending in netcore.cs:

  • These are .NET Core only, so #if NET checks are removed entirely and code is made unconditional
  • Fixed formatting where lines were awkwardly split due to removed #if directives

For other files that also build for netstandard/netframework:

  • Replaced NET9_0_OR_GREATER / NET10_0_OR_GREATER with just NET
  • This maintains the distinction between .NET Core and netstandard/netframework
  • Conditions use #if NET ... #else ... #endif structure

For test files:

  • Replaced NET9_0_OR_GREATER / NET10_0_OR_GREATER with NET since test projects target both .NET Core and .NET Framework

Files Changed

Source files:

  • System.Private.CoreLib Base64 helpers, IAsyncEnumerable/IAsyncEnumerator, ConfiguredCancelableAsyncEnumerable
  • Common/src crypto helpers (HexConverter uses #if NET ... #else structure)
  • Microsoft.Bcl.Cryptography, Microsoft.Bcl.Memory
  • Microsoft.Extensions.Caching, Configuration.Binder, DependencyInjection, Options
  • System.Collections.Immutable, Diagnostics.DiagnosticSource, DirectoryServices.Protocols
  • System.Formats.Asn1, System.Formats.Nrbf, System.Numerics.Tensors (netcore files updated with clean formatting)
  • System.Security.Cryptography.Pkcs/Xml, System.Text.Json, System.Threading.Channels
  • Reference assemblies
  • Test baseline files for Microsoft.Extensions.Options source generators

Test files:

  • Common/tests/System/Security/Cryptography/ByteUtils.cs
  • Common/tests/System/Security/Cryptography/X509Certificates/X509CertificateLoaderPkcs12Tests.cs
  • Common/tests/System/Security/Cryptography/X509Certificates/X509CertificateLoaderPkcs12CollectionTests.cs
  • Microsoft.Extensions.Caching.Memory/tests/AltLookupTests.cs
  • System.Formats.Asn1/tests/Writer/*.cs
  • System.Text.Json/tests/Common/MetadataTests.cs
  • System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/MetadataTests.cs
  • System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs

Note: Searched for older version constants (NET8_0_OR_GREATER, NET7_0_OR_GREATER, NET6_0_OR_GREATER, etc.) - none were found in the source files.

Original prompt

This repo no longer builds for .NET Core versions older than 10. As such, search for all occurrences of compilation constants like NET10_0_OR_GREATER, NET9_0_OR_GREATER, etc. If they're in files that also build for netstandard, replace them with just NET. If they're in files that only build for .NET 10+, whatever is protected by those constants can be unconditionally included, and anything po


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 7, 2026
@stephentoub stephentoub added area-Meta and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 7, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Copilot AI and others added 2 commits January 7, 2026 02:02
…oreLib

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title [WIP] Update compilation constants for .NET Core versioning Jan 7, 2026
Copilot AI requested a review from stephentoub January 7, 2026 02:20
@stephentoub

Copy link
Copy Markdown
Member

@copilot, what about NET8_0_OR_GREATER, NET7_0_OR_GREATER, NET6_0_OR_GREATER, etc. Any of those that also need to be cleaned up?

Comment thread src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs Outdated

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, what about NET8_0_OR_GREATER, NET7_0_OR_GREATER, NET6_0_OR_GREATER, etc. Any of those that also need to be cleaned up?

I searched for NET8_0_OR_GREATER, NET7_0_OR_GREATER, NET6_0_OR_GREATER, and other older version constants in src/libraries/ (excluding tests, baselines, and gen folders). No occurrences were found - it appears those were already cleaned up previously or never existed in the source files that needed updating.

@stephentoub

Copy link
Copy Markdown
Member

@copilot, there are build failures, e.g.

Build FAILED.

D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Runtime\CompilerServices\ConfiguredCancelableAsyncEnumerable.cs(13,26): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=netstandard2.0]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Collections\Generic\IAsyncEnumerable.cs(11,26): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=netstandard2.0]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Collections\Generic\IAsyncEnumerator.cs(11,27): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=netstandard2.0]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\TaskAsyncEnumerableExtensions.cs(26,30): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=netstandard2.0]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\TaskAsyncEnumerableExtensions.cs(36,30): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=netstandard2.0]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Runtime\CompilerServices\ConfiguredCancelableAsyncEnumerable.cs(13,26): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=net462]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Collections\Generic\IAsyncEnumerable.cs(11,26): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=net462]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Collections\Generic\IAsyncEnumerator.cs(11,27): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=net462]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\TaskAsyncEnumerableExtensions.cs(26,30): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=net462]
D:\a\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\TaskAsyncEnumerableExtensions.cs(36,30): error CS9240: Target runtime doesn't support by-ref-like generics. [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.AsyncInterfaces\src\Microsoft.Bcl.AsyncInterfaces.csproj::TargetFramework=net462]
D:\a\_work\1\s\src\libraries\Common\src\System\HexConverter.cs(235,27): error CS9244: The type 'HexConverter.SpanCasingPair' may not be a ref struct or a type parameter allowing ref structs in order to use it as parameter 'TState' in the generic type or method 'string.Create<TState>(int, TState, SpanAction<char, TState>)' [D:\a\_work\1\s\src\libraries\Microsoft.Bcl.Cryptography\src\Microsoft.Bcl.Cryptography.csproj::TargetFramework=netstandard2.1]
    0 Warning(s)
    11 Error(s)

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
…hared files

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, there are build failures, e.g.

Build FAILED.

...

Fixed in 156bd27. The issue was that files like IAsyncEnumerable.cs, IAsyncEnumerator.cs, ConfiguredCancelableAsyncEnumerable.cs, and TaskAsyncEnumerableExtensions.cs are shared with Microsoft.Bcl.AsyncInterfaces which targets netstandard2.0 and net462. I incorrectly removed the #if NET9_0_OR_GREATER guards entirely instead of replacing them with #if NET. These files now correctly use #if NET to protect the allows ref struct constraint.

@stephentoub stephentoub marked this pull request as ready for review January 7, 2026 04:27
Copilot AI review requested due to automatic review settings January 7, 2026 04:27
Comment thread src/libraries/Microsoft.Extensions.Options/gen/Emitter.cs
Comment thread src/libraries/Common/src/System/HexConverter.cs Outdated
…nstead of NET10_0_OR_GREATER

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Copilot AI requested a review from MihaZupan January 7, 2026 14:28
@stephentoub

Copy link
Copy Markdown
Member

@copilot, please search the repo for any remaining NET9_0_OR_GREATER or NET10_0_OR_GREATER constants in any files.

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, please search the repo for any remaining NET9_0_OR_GREATER or NET10_0_OR_GREATER constants in any files.

Found and fixed 18 remaining occurrences in test files (commit 6a4b0e8):

  • Common/tests/System/Security/Cryptography/ByteUtils.cs - 3 occurrences
  • Common/tests/System/Security/Cryptography/X509Certificates/X509CertificateLoaderPkcs12Tests.cs - 2 occurrences
  • Common/tests/System/Security/Cryptography/X509Certificates/X509CertificateLoaderPkcs12CollectionTests.cs - 2 occurrences
  • Microsoft.Extensions.Caching.Memory/tests/AltLookupTests.cs - 3 occurrences
  • System.Formats.Asn1/tests/Writer/PushPopSetOf.cs - 1 occurrence
  • System.Formats.Asn1/tests/Writer/Asn1WriterTests.cs - 1 occurrence
  • System.Formats.Asn1/tests/Writer/SimpleWriterTests.cs - 2 occurrences
  • System.Text.Json/tests/Common/MetadataTests.cs - 2 occurrences
  • System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/MetadataTests.cs - 1 occurrence
  • System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs - 1 occurrence

All replaced with NET to maintain the .NET Core vs .NET Framework distinction. No remaining occurrences in src/libraries.

@stephentoub

Copy link
Copy Markdown
Member

No remaining occurrences in src/libraries.

@copilot, are there remaining uses elsewhere than src/libraries?

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

No remaining occurrences in src/libraries.

@copilot, are there remaining uses elsewhere than src/libraries?

No, there are no remaining occurrences anywhere in the repo. I searched the entire repository (excluding .git/, .dotnet/, and /docs/) for NET9_0_OR_GREATER and NET10_0_OR_GREATER in .cs, .csproj, .targets, and .props files - the search returned empty results.

@stephentoub stephentoub merged commit 313982d into main Jan 7, 2026
140 of 145 checks passed
@stephentoub stephentoub deleted the copilot/update-compilation-constants branch January 7, 2026 21:05
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

5 participants