Skip to content

feat: align all components to SemVer 2.0 for version comparison #520

Description

@JusterZhu

Problem

The GeneralUpdate SDK uses System.Version (Version.TryParse, new Version(string)) for all version comparison logic across Core, Extension, and Drivelution components. System.Version does not support SemVer 2.0 — it rejects prerelease suffixes (e.g. "10.5.0-beta.2") and build metadata, causing either silent "no update needed" (returning false from TryParse) or a FormatException (from new Version()).

Since all NuGet packages are already versioned as 10.5.0-beta.2 (valid SemVer 2.0), this means a client configured with version "10.5.0-beta.2" would never see an update — the comparison silently skips.

Solution

Replace all System.Version usage with a dedicated Semver utility class that follows SemVer 2.0, aligned with the existing implementation in GeneralUpdate.Infrastructure.Common/Utilitys/Semver.cs.

Changes

New files

  • src/c#/GeneralUpdate.Core/Utilities/Semver.cs — SemVer 2.0 validation, parsing, comparison, normalization
  • src/c#/GeneralUpdate.Extension/Utilities/Semver.cs — Same, for Extension (netstandard2.0 compatible)
  • src/c#/GeneralUpdate.Drivelution/Core/Utilities/Semver.cs — Same, for Drivelution

Modified files (Core)

  • Download/DownloadPlanBuilder.csParseVersion() now returns SemVersion?, all operators use SemVer 2.0 ordering
  • Strategy/OssStrategy.cs — Replaced new Version() + Version.TryParse with Semver.TryParse
  • Strategy/ClientStrategy.csCheckFail() uses Semver.TryParse
  • Configuration/UpdateConfiguration.cs — Default ClientVersion from "1.0.0.0""1.0.0"

Modified files (Extension)

  • Compatibility/VersionCompatibilityChecker.cs — All Version.TryParse + </>Semver.TryParse + SemVersion operators

Modified files (Drivelution)

  • Core/Utilities/VersionComparer.cs — Marked [Obsolete], delegates to Semver

Tests

  • CoreTest/Configuration/UpdateConfigurationTests.cs — Assert "1.0.0" instead of "1.0.0.0"
  • DrivelutionTest/Utilities/VersionComparerAndRestartHelperTests.cs — Updated for aligned Semver

Bugs fixed incidentally

  1. CVP matching never worked: Old code used fromVer == localVersion on nullable System.Version (reference type without == overload → always false)
  2. OssStrategy NPE: assets.Max()!.Value on an empty parsed-collection would NPE — added guard

Backward compatibility

  • Legacy 4-part versions (e.g. "1.0.0.0") are accepted and normalized to "1.0.0"
  • HasUpdate() still returns true when version is unparseable ("safe side" policy)
  • All existing SemVer 3-part comparisons produce identical results
  • Drivelution VersionComparer is preserved as an [Obsolete] delegate

Breaking changes

  • 4-part version fourth segment is discarded (required by SemVer 2.0)
  • Drivelution VersionComparer no longer throws FormatException on invalid input (returns 0 instead)
  • Version numbers exceeding int.MaxValue (~2.1e9) are treated as invalid

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuresNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions