@@ -25,42 +25,49 @@ internal partial class Runtime
25
25
internal sealed class RuntimeVersion : IComparable < RuntimeVersion >
26
26
{
27
27
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 ;
31
32
public string FullPath
32
33
{
33
34
get
34
35
{
35
- var preview = IsPreview ? $ "-preview. { PreviewVersion } " : "" ;
36
- var version = Version + preview ;
36
+ var preRelease = IsPreRelease ? $ "-{ preReleaseVersionType } . { preReleaseVersion } " : "" ;
37
+ var version = this . version + preRelease ;
37
38
return Path . Combine ( dir , version ) ;
38
39
}
39
40
}
40
41
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 )
48
43
{
49
44
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 ) )
52
47
{
53
- PreviewVersion = MakeVersion ( previewVersion ) ;
48
+ this . preReleaseVersionType = preReleaseVersionType ;
49
+ this . preReleaseVersion = Version . Parse ( preReleaseVersion ) ;
54
50
}
55
51
}
56
52
57
53
public int CompareTo ( RuntimeVersion ? other )
58
54
{
59
- var c = Version . CompareTo ( other ? . Version ) ;
60
- if ( c == 0 && IsPreview )
55
+ var c = version . CompareTo ( other ? . version ) ;
56
+ if ( c == 0 && IsPreRelease )
61
57
{
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 ) ;
63
69
}
70
+
64
71
return c ;
65
72
}
66
73
@@ -72,7 +79,7 @@ public override bool Equals(object? obj) =>
72
79
public override string ToString ( ) => FullPath ;
73
80
}
74
81
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+)\]$" ) ]
76
83
private static partial Regex RuntimeRegex ( ) ;
77
84
78
85
/// <summary>
@@ -90,7 +97,7 @@ private static Dictionary<string, RuntimeVersion> ParseRuntimes(IList<string> li
90
97
var match = RuntimeRegex ( ) . Match ( r ) ;
91
98
if ( match . Success )
92
99
{
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 ) ) ;
94
101
}
95
102
} ) ;
96
103
0 commit comments