feat: align all components to SemVer 2.0 for version comparison#521
Merged
Conversation
Replace all System.Version usage (Version.TryParse, new Version(string)) with a dedicated Semver utility class following SemVer 2.0, aligned with GeneralUpdate.Infrastructure.Common/Utilitys/Semver.cs. New files: - GeneralUpdate.Core/Utilities/Semver.cs - GeneralUpdate.Extension/Utilities/Semver.cs - GeneralUpdate.Drivelution/Core/Utilities/Semver.cs Modified: - DownloadPlanBuilder, OssStrategy, ClientStrategy — switch to Semver.TryParse - VersionCompatibilityChecker — Semver-based comparison - VersionComparer — [Obsolete] wrapper delegating to Semver - Default ClientVersion: "1.0.0.0" → "1.0.0" - Updated tests for new default and Semver alignment Bugs fixed incidentally: 1. CVP matching used reference equality on Version objects (never worked) 2. OssStrategy LastVersion NPE on empty parse results Closes #520 Co-Authored-By: Claude <noreply@anthropic.com>
- Replace range syntax (input[..]) with Substring for netstandard2.0 - Add missing using System.Linq for string.All() extension method - Applied to all 3 copies: Core, Extension, Drivelution Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request replaces System.Version-based version parsing/comparison across Core, Extension, and Drivelution with a SemVer 2.0-compatible Semver utility (including prerelease handling and legacy 4-part normalization), preventing “silent no update” behavior when versions include prerelease suffixes.
Changes:
- Added SemVer 2.0 parsing/comparison utilities to Core, Extension, and Drivelution; updated comparison call-sites to use
Semver/SemVersion. - Updated default
ClientVersionto"1.0.0"and aligned examples/docs/tests accordingly. - Marked Drivelution
VersionCompareras[Obsolete]and delegated implementation toSemver; updated Drivelution tests to match new behavior.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/DrivelutionTest/Utilities/VersionComparerAndRestartHelperTests.cs | Updates expectations to match SemVer-based comparison behavior (invalid/overflow inputs return 0, legacy 4-part accepted). |
| tests/CoreTest/Configuration/UpdateConfigurationTests.cs | Adjusts assertion for new default client version string (1.0.0). |
| src/c#/GeneralUpdate.Extension/Utilities/Semver.cs | Adds SemVer 2.0 parsing/normalization/comparison implementation for Extension. |
| src/c#/GeneralUpdate.Extension/Examples/ExtensionExample.cs | Updates example host version to 3-part SemVer. |
| src/c#/GeneralUpdate.Extension/Compatibility/VersionCompatibilityChecker.cs | Migrates host/version constraint checks and “latest compatible” selection to SemVer comparisons. |
| src/c#/GeneralUpdate.Drivelution/Core/Utilities/VersionComparer.cs | Converts existing comparer into an obsolete wrapper delegating to Semver. |
| src/c#/GeneralUpdate.Drivelution/Core/Utilities/Semver.cs | Adds SemVer 2.0 parsing/normalization/comparison implementation for Drivelution. |
| src/c#/GeneralUpdate.Core/Utilities/Semver.cs | Adds SemVer 2.0 parsing/normalization/comparison implementation for Core. |
| src/c#/GeneralUpdate.Core/Strategy/OssStrategy.cs | Switches OSS version filtering and LastVersion computation to SemVer parsing/comparison. |
| src/c#/GeneralUpdate.Core/Strategy/ClientStrategy.cs | Updates failed-version guard logic to use SemVer parsing/comparison. |
| src/c#/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs | Migrates update planning/version filtering to SemVer; adjusts CVP matching logic. |
| src/c#/GeneralUpdate.Core/Configuration/VersionIdentity.cs | Updates version string documentation example to SemVer 3-part format. |
| src/c#/GeneralUpdate.Core/Configuration/VersionEntry.cs | Updates version string documentation example to SemVer 3-part format. |
| src/c#/GeneralUpdate.Core/Configuration/UpdateRequestBuilder.cs | Updates JSON example to use "1.0.0" for ClientVersion. |
| src/c#/GeneralUpdate.Core/Configuration/UpdateConfiguration.cs | Changes default ClientVersion from "1.0.0.0" to "1.0.0". |
| src/c#/GeneralUpdate.Core/Configuration/AppMetadataDiscoverer.cs | Updates comment examples to reflect the new default client version format. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Extract .Value from SemVersion? before comparison in Where lambda - Use .Value in IsCompatible to avoid SemVersion? >= SemVersion? → bool? - Keep non-nullable local copies (cv, uv) for the rest of the method Co-Authored-By: Claude <noreply@anthropic.com>
The previous implementation split the full version string (including prerelease/build metadata) on '.'/'-'/'+', causing false positives for legitimate build-metadata timestamps like 1.0.0+20130313144700. Now only the core triplet (everything before '-' or '+') is checked. Update Drivelution test accordingly: remove 999999999999* cases from valid-versions (they exceed int range). Co-Authored-By: Claude <noreply@anthropic.com>
SysNumOverflow no longer scans prerelease/build metadata tokens, so prerelease identifiers like 999999999999 are valid and compare correctly as long. Test assertion updated to match. Co-Authored-By: Claude <noreply@anthropic.com>
Collaborator
Author
|
All 5 Copilot review suggestions have been addressed across 4 fix commits:
Additional fixes:
CI is now ✅ green. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace all
System.Versionusage across Core, Extension, and Drivelution with a unifiedSemverutility class following SemVer 2.0, aligned withGeneralUpdate.Infrastructure.Common/Utilitys/Semver.cs.All NuGet packages are already versioned as
10.5.0-beta.2(valid SemVer 2.0), but the SDK code could not compare such versions becauseSystem.Version.TryParse("10.5.0-beta.2")returnsfalse, causing silent "no update" behavior. This PR fixes that.Key changes
DownloadPlanBuilder,OssStrategy,ClientStrategy— allVersion.TryParse/new Version()→Semver.TryParse+SemVersionoperatorsVersionCompatibilityChecker— same migrationVersionComparer→[Obsolete]wrapper delegating to newSemverClientVersionfrom"1.0.0.0"→"1.0.0"Utilities/Semver.csin each of Core, Extension, DrivelutionBugs fixed incidentally
fromVer == localVersionused reference equality onVersion(class), alwaysfalseassets.Max()!.Valueon empty parsed collectionBackward compatibility
"1.0.0.0") accepted and normalizedVersionComparerpreserved as[Obsolete]delegateCloses #520
🤖 Generated with Claude Code