Skip to content

Replace NET8_0_OR_GREATER with NET across all source files#118363

Merged
agocke merged 2 commits intomainfrom
copilot/fix-109226
Aug 5, 2025
Merged

Replace NET8_0_OR_GREATER with NET across all source files#118363
agocke merged 2 commits intomainfrom
copilot/fix-109226

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 4, 2025

Since .NET 8.0 is now the minimum supported version (as defined by NetCoreAppMinimum = net8.0 in Directory.Build.props), the conditional compilation symbol NET8_0_OR_GREATER can be simplified to NET throughout the codebase.

Changes Made

This PR systematically replaces all 258 occurrences of NET8_0_OR_GREATER across 114 source files with the simpler NET symbol. The changes include:

  • #if NET8_0_OR_GREATER#if NET
  • #if !NET8_0_OR_GREATER#if !NET
  • #elif NET8_0_OR_GREATER#elif NET
  • #endif // NET8_0_OR_GREATER#endif // NET
  • #endif // !NET8_0_OR_GREATER#endif // !NET

Rationale

The replacement is safe because:

  1. For .NET targets: The NET symbol is defined for .NET 5+ and since we now require .NET 8.0 minimum, any .NET target will be .NET 8.0 or greater
  2. For .NET Standard/Framework targets: Neither NET8_0_OR_GREATER nor NET are defined, so the conditional compilation behavior remains unchanged

Examples

Before:

#if NET8_0_OR_GREATER
[Obsolete("Legacy formatter", DiagnosticId = "SYSLIB0051")]
#endif
protected MyException(SerializationInfo info, StreamingContext context) : base(info, context) { }

After:

#if NET
[Obsolete("Legacy formatter", DiagnosticId = "SYSLIB0051")]
#endif
protected MyException(SerializationInfo info, StreamingContext context) : base(info, context) { }

Affected Libraries

The changes span across many core libraries including:

  • Microsoft.Bcl.TimeProvider
  • System.Text.Json
  • System.Diagnostics.EventLog
  • System.Reflection.Metadata
  • Various exception classes and serialization-related code

Verification

  • All occurrences have been successfully replaced (0 remaining)
  • Libraries build successfully with the changes
  • No functional behavior changes - this is purely a conditional compilation symbol cleanup

Fixes #109226.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Copilot AI changed the title [WIP] Cleanup NET8_0_OR_GREATER symbol Replace NET8_0_OR_GREATER with NET across all source files Aug 4, 2025
Copilot AI requested a review from agocke August 4, 2025 22:58
@am11
Copy link
Copy Markdown
Member

am11 commented Aug 5, 2025

@copilot, these two as well:

src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64Helper.cs:#if NET8_0
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultJsonTypeInfoResolver.Helpers.cs:#if NET8_0

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Aug 5, 2025

these two as well:

@am11 NET8_0 != NET8_0_OR_GREATER. I do not think it would be correct that change these.

@agocke agocke marked this pull request as ready for review August 5, 2025 18:35
Copilot AI review requested due to automatic review settings August 5, 2025 18:35
Copy link
Copy Markdown
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 systematically replaces all 258 occurrences of the conditional compilation symbol NET8_0_OR_GREATER with NET across 114 source files. This is a cleanup change that takes advantage of the fact that .NET 8.0 is now the minimum supported version, making the simpler NET symbol equivalent to NET8_0_OR_GREATER in all supported scenarios.

Key changes:

  • Replacement of #if NET8_0_OR_GREATER with #if NET throughout the codebase
  • Corresponding updates to #if !NET8_0_OR_GREATER#if !NET
  • Updates to comment references in #endif statements

Reviewed Changes

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

Show a summary per file
File Description
src/tasks/Common/JoinedString.cs Updates conditional compilation for interpolated string handlers
src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs Updates obsolete attribute conditional compilation
src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs Updates conditional compilation for event logging
src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/DefaultPartitionedRateLimiter.cs Updates ConfigureAwait options conditional compilation
src/libraries/System.Threading.Channels/src/System/Threading/Channels/ChannelClosedException.netcoreapp.cs Updates exception serialization attributes
src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.cs Updates UTF-8 validation and encoding conditionals
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/VersionConverter.cs Updates span allocation for version formatting
src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs Updates search values and line counting logic
src/libraries/System.Text.Json/src/System/Text/Json/JsonException.cs Updates exception serialization attributes
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParseException.cs Updates exception serialization attributes
Various System.Security.* libraries Updates exception serialization attributes across security components
Various System.DirectoryServices.* libraries Updates exception serialization attributes for directory services
Various configuration and data libraries Updates exception serialization and utility method conditionals
Test files Updates test conditional compilation for .NET version-specific features

@agocke agocke enabled auto-merge (squash) August 5, 2025 18:37
@agocke
Copy link
Copy Markdown
Member

agocke commented Aug 5, 2025

/ba-g test was disabled and tracked in #114912

1 similar comment
@jkotas
Copy link
Copy Markdown
Member

jkotas commented Aug 5, 2025

/ba-g test was disabled and tracked in #114912

@agocke agocke merged commit 565b6d3 into main Aug 5, 2025
152 of 155 checks passed
@jkotas jkotas deleted the copilot/fix-109226 branch August 5, 2025 23:56
@xtqqczze
Copy link
Copy Markdown
Contributor

xtqqczze commented Aug 6, 2025

Some of these directives could have been removed entirely, see #118421 for context. It looks like Copilot may have overlooked that detail.

@github-actions github-actions Bot locked and limited conversation to collaborators Sep 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleanup NET8_0_OR_GREATER symbol

6 participants