@@ -25,42 +25,49 @@ internal partial class Runtime
2525 internal sealed class RuntimeVersion : IComparable < RuntimeVersion >
2626 {
2727 private readonly string dir ;
28- private Version Version { get ; }
29- private Version ? PreviewVersion { get ; } = null ;
30- private bool IsPreview => PreviewVersion is not null ;
28+ private readonly Version version ;
29+ private readonly Version ? preReleaseVersion ;
30+ private readonly string ? preReleaseVersionType ;
31+ private bool IsPreRelease => preReleaseVersionType is not null && preReleaseVersion is not null ;
3132 public string FullPath
3233 {
3334 get
3435 {
35- var preview = IsPreview ? $ "-preview. { PreviewVersion } " : "" ;
36- var version = Version + preview ;
36+ var preRelease = IsPreRelease ? $ "-{ preReleaseVersionType } . { preReleaseVersion } " : "" ;
37+ var version = this . version + preRelease ;
3738 return Path . Combine ( dir , version ) ;
3839 }
3940 }
4041
41- private static Version MakeVersion ( string version )
42- {
43- var versionParts = version . Split ( '.' ) ;
44- return new Version ( int . Parse ( versionParts [ 0 ] ) , int . Parse ( versionParts [ 1 ] ) , int . Parse ( versionParts [ 2 ] ) ) ;
45- }
46-
47- public RuntimeVersion ( string dir , string version , string previewVersion )
42+ public RuntimeVersion ( string dir , string version , string preReleaseVersionType , string preReleaseVersion )
4843 {
4944 this . dir = dir ;
50- Version = MakeVersion ( version ) ;
51- if ( ! string . IsNullOrEmpty ( previewVersion ) )
45+ this . version = Version . Parse ( version ) ;
46+ if ( ! string . IsNullOrEmpty ( preReleaseVersion ) && ! string . IsNullOrEmpty ( preReleaseVersionType ) )
5247 {
53- PreviewVersion = MakeVersion ( previewVersion ) ;
48+ this . preReleaseVersionType = preReleaseVersionType ;
49+ this . preReleaseVersion = Version . Parse ( preReleaseVersion ) ;
5450 }
5551 }
5652
5753 public int CompareTo ( RuntimeVersion ? other )
5854 {
59- var c = Version . CompareTo ( other ? . Version ) ;
60- if ( c == 0 && IsPreview )
55+ var c = version . CompareTo ( other ? . version ) ;
56+ if ( c == 0 && IsPreRelease )
6157 {
62- return other ! . IsPreview ? PreviewVersion ! . CompareTo ( other ! . PreviewVersion ) : - 1 ;
58+ if ( ! other ! . IsPreRelease )
59+ {
60+ return - 1 ;
61+ }
62+
63+ // Both are pre-release like runtime versions.
64+ // The pre-release version types are sorted alphabetically (e.g. alpha, beta, preview, rc)
65+ // and the pre-release version types are more important that the pre-release version numbers.
66+ return preReleaseVersionType != other ! . preReleaseVersionType
67+ ? preReleaseVersionType ! . CompareTo ( other ! . preReleaseVersionType )
68+ : preReleaseVersion ! . CompareTo ( other ! . preReleaseVersion ) ;
6369 }
70+
6471 return c ;
6572 }
6673
@@ -72,7 +79,7 @@ public override bool Equals(object? obj) =>
7279 public override string ToString ( ) => FullPath ;
7380 }
7481
75- [ GeneratedRegex ( @"^(\S+)\s(\d+\.\d+\.\d+)(-preview \.(\d+\.\d+\.\d+))?\s\[(\S+)\]$" ) ]
82+ [ GeneratedRegex ( @"^(\S+)\s(\d+\.\d+\.\d+)(-([a-z]+) \.(\d+\.\d+\.\d+))?\s\[(\S+)\]$" ) ]
7683 private static partial Regex RuntimeRegex ( ) ;
7784
7885 /// <summary>
@@ -90,7 +97,7 @@ private static Dictionary<string, RuntimeVersion> ParseRuntimes(IList<string> li
9097 var match = RuntimeRegex ( ) . Match ( r ) ;
9198 if ( match . Success )
9299 {
93- runtimes . AddOrUpdate ( match . Groups [ 1 ] . Value , new RuntimeVersion ( match . Groups [ 5 ] . Value , match . Groups [ 2 ] . Value , match . Groups [ 4 ] . Value ) ) ;
100+ runtimes . AddOrUpdate ( match . Groups [ 1 ] . Value , new RuntimeVersion ( match . Groups [ 6 ] . Value , match . Groups [ 2 ] . Value , match . Groups [ 4 ] . Value , match . Groups [ 5 ] . Value ) ) ;
94101 }
95102 } ) ;
96103
0 commit comments