Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 7, 2026

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
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 Remove NET9_0_OR_GREATER and NET10_0_OR_GREATER preprocessor constants Jan 7, 2026
Copilot AI requested a review from stephentoub January 7, 2026 02:20
@stephentoub
Copy link
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?

Copy link
Contributor Author

Copilot AI commented Jan 7, 2026

@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
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>
Copy link
Contributor Author

Copilot AI commented Jan 7, 2026

@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
Copy link
Contributor

Copilot AI left a comment

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 performs a systematic cleanup of obsolete .NET version-specific preprocessor constants (NET9_0_OR_GREATER and NET10_0_OR_GREATER) since the repository no longer builds for .NET versions older than 10. The changes follow a clear strategy based on file location and target frameworks.

Key changes:

  • System.Private.CoreLib files: Replace version constants with #if NET to maintain compatibility with packages targeting netstandard/netframework
  • Files in netcore directories or ending in netcore.cs: Remove conditionals entirely as they only build for .NET Core
  • Other multi-target files: Replace with #if NET to distinguish between .NET Core and netstandard/netframework

Reviewed changes

Copilot reviewed 89 out of 89 changed files in this pull request and generated no comments.

Show a summary per file
File Description
System.Threading.Channels/AsyncOperation.cs Replaced NET9_0_OR_GREATER with NET for bool/int field type selection
System.Text.Json/EnumConverter.cs Replaced NET9_0_OR_GREATER with NET for alternate lookup APIs
System.Text.Json/JsonHelpers.cs Replaced NET9_0_OR_GREATER with NET for dictionary alternate lookup
System.Security.Cryptography.Xml/SignedXmlDebugLog.cs Replaced NET9_0_OR_GREATER with NET for ToHexStringLower usage
System.Security.Cryptography.Pkcs/SignerInfo.cs Replaced NET9_0_OR_GREATER with NET for AsnWriter.Encode callback
System.Private.CoreLib (IAsyncEnumerable/Enumerator) Replaced NET9_0_OR_GREATER/NET10_0_OR_GREATER with NET for ref struct constraints
System.Private.CoreLib/Base64 helpers Removed NET9_0_OR_GREATER conditionals around CompExactlyDependsOn attributes and ARM intrinsics
System.Numerics.Tensors/netcore files Removed all version conditionals as these only build for .NET Core
System.Numerics.Tensors reference assembly Replaced NET9_0_OR_GREATER with NET for allows ref struct constraints
System.Formats.Nrbf/Asn1 Replaced NET9_0_OR_GREATER/NET10_0_OR_GREATER with NET
System.DirectoryServices.Protocols Replaced NET10_0_OR_GREATER with NET for Obsolete attributes
System.Diagnostics.DiagnosticSource Replaced NET9_0_OR_GREATER with NET for Activity/MeterListener
System.Collections.Immutable Replaced NET9_0_OR_GREATER with NET for allows ref struct constraints
Microsoft.Extensions.* Replaced version constants with NET for various features
Microsoft.Bcl.* Replaced version constants and adjusted type forwards
Common/src/System Replaced NET10_0_OR_GREATER with NET in crypto helpers and HexConverter

All changes appear to be systematic and consistent with the stated strategy. The PR correctly maintains compatibility for packages that target netstandard/netframework while simplifying conditional compilation for .NET Core-only code.

…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
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>
Copy link
Contributor Author

Copilot AI commented Jan 7, 2026

@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
Member

No remaining occurrences in src/libraries.

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

Copy link
Contributor Author

Copilot AI commented Jan 7, 2026

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
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