[PR #1135] Consolidate NETFRAMEWORK/NETSTANDARD compile flags into LEGACY_DOTNET #1569

Closed
opened 2026-01-29 22:21:10 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1135

State: closed
Merged: Yes


Consolidate compile flags for NETFRAMEWORK and NETSTANDARD

Summary of Changes

This PR consolidates scattered NETFRAMEWORK and NETSTANDARD2_0 compile flags into a single, clearer LEGACY_DOTNET constant.

What Changed

  1. Added LEGACY_DOTNET compile constant in SharpCompress.csproj

    • Defined for net48 and netstandard20 targets
    • Provides clear semantic meaning: code for legacy .NET platforms vs. modern .NET
  2. Replaced 41 occurrences across 25 files:

    • #if !NETFRAMEWORK && !NETSTANDARD2_0#if !LEGACY_DOTNET
    • #if NETFRAMEWORK || NETSTANDARD2_0#if LEGACY_DOTNET
    • #if !NETSTANDARD2_0 && !NETSTANDARD2_1 && !NETFRAMEWORK#if !LEGACY_DOTNET
    • #if NETFRAMEWORK || NETSTANDARD#if LEGACY_DOTNET
    • #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER#if !LEGACY_DOTNET
  3. Additional simplifications:

    • Removed obsolete NETCF (NET Compact Framework) flag - not a supported target
    • Fixed typo: NET60_OR_GREATERNET6_0_OR_GREATER
    • Changed NET6_0_OR_GREATERNET8_0_OR_GREATER (5 occurrences in 3 files)
    • Total: 6 additional simplifications

Benefits

  • Clearer intent: LEGACY_DOTNET communicates purpose better than framework checks
  • 🔧 Easier maintenance: Single source of truth for legacy vs. modern .NET
  • 📉 Reduced duplication: No need to repeat complex multi-framework conditions
  • 🐛 Fewer errors: Single constant reduces typos and inconsistent checks
  • 🎯 Better targeting: NET8_0_OR_GREATER aligns with actual project targets (net8.0, net10.0)

Verification

  • Analyze codebase and understand compile flag patterns
  • Add custom compile constant (LEGACY_DOTNET)
  • Replace all patterns with consolidated flag
  • Handle edge cases
  • Build all targets successfully (net48, netstandard20, net8.0, net10.0)
  • Run tests (984 tests pass on net10.0)
  • Apply additional simplifications
  • Change NET6_0_OR_GREATER to NET8_0_OR_GREATER per feedback
  • Format code with CSharpier
  • Code review (no issues)
  • Security scan (no issues)
Original prompt

This section details on the original issue you should resolve

<issue_title>Consolidate compile flags</issue_title>
<issue_description>NETFRAMEWORK and NETSTANDARD should be combined into a single compile flags to be used in code and replaced.

See if there are opportunities for other simplification</issue_description>

Comments on the Issue (you are @copilot in this section)


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

**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/1135 **State:** closed **Merged:** Yes --- ## Consolidate compile flags for NETFRAMEWORK and NETSTANDARD ### Summary of Changes This PR consolidates scattered `NETFRAMEWORK` and `NETSTANDARD2_0` compile flags into a single, clearer `LEGACY_DOTNET` constant. ### What Changed 1. **Added `LEGACY_DOTNET` compile constant** in SharpCompress.csproj - Defined for `net48` and `netstandard20` targets - Provides clear semantic meaning: code for legacy .NET platforms vs. modern .NET 2. **Replaced 41 occurrences** across 25 files: - `#if !NETFRAMEWORK && !NETSTANDARD2_0` → `#if !LEGACY_DOTNET` - `#if NETFRAMEWORK || NETSTANDARD2_0` → `#if LEGACY_DOTNET` - `#if !NETSTANDARD2_0 && !NETSTANDARD2_1 && !NETFRAMEWORK` → `#if !LEGACY_DOTNET` - `#if NETFRAMEWORK || NETSTANDARD` → `#if LEGACY_DOTNET` - `#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER` → `#if !LEGACY_DOTNET` 3. **Additional simplifications**: - Removed obsolete `NETCF` (NET Compact Framework) flag - not a supported target - Fixed typo: `NET60_OR_GREATER` → `NET6_0_OR_GREATER` - **Changed `NET6_0_OR_GREATER` → `NET8_0_OR_GREATER`** (5 occurrences in 3 files) - Total: 6 additional simplifications ### Benefits - ✨ **Clearer intent**: `LEGACY_DOTNET` communicates purpose better than framework checks - 🔧 **Easier maintenance**: Single source of truth for legacy vs. modern .NET - 📉 **Reduced duplication**: No need to repeat complex multi-framework conditions - 🐛 **Fewer errors**: Single constant reduces typos and inconsistent checks - 🎯 **Better targeting**: `NET8_0_OR_GREATER` aligns with actual project targets (net8.0, net10.0) ### Verification ✅ - [x] Analyze codebase and understand compile flag patterns - [x] Add custom compile constant (`LEGACY_DOTNET`) - [x] Replace all patterns with consolidated flag - [x] Handle edge cases - [x] Build all targets successfully (net48, netstandard20, net8.0, net10.0) - [x] Run tests (984 tests pass on net10.0) - [x] Apply additional simplifications - [x] Change NET6_0_OR_GREATER to NET8_0_OR_GREATER per feedback - [x] Format code with CSharpier - [x] Code review (no issues) - [x] Security scan (no issues) <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Consolidate compile flags</issue_title> > <issue_description>NETFRAMEWORK and NETSTANDARD should be combined into a single compile flags to be used in code and replaced. > > See if there are opportunities for other simplification</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes adamhathcock/sharpcompress#1134 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
claunia added the pull-request label 2026-01-29 22:21:10 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1569