Skip to content

Commit 52485ec

Browse files
authored
Get full parsable version part (#2646)
1 parent 5fe0c78 commit 52485ec

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ internal static bool TryGetVersionFromFrameworkName(string frameworkName, out Ve
194194
}
195195

196196
// Version.TryParse does not handle thing like 3.0.0-WORD
197-
private static string GetParsableVersionPart(string fullVersionName) => new string(fullVersionName.TakeWhile(c => char.IsDigit(c) || c == '.').ToArray());
197+
internal static string GetParsableVersionPart(string fullVersionName) => new string(fullVersionName.TakeWhile(c => char.IsDigit(c) || c == '.').ToArray());
198198

199199
private static CoreRuntime GetPlatformSpecific(CoreRuntime fallback)
200200
{

src/BenchmarkDotNet/Validators/DotNetSdkVersionValidator.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,9 @@ private static IEnumerable<Version> GetInstalledDotNetSdks(string? customDotNetC
111111
var versions = new List<Version>(lines.Count());
112112
foreach (var line in lines)
113113
{
114-
// Each line will start with the SDK version followed by the SDK path. Since we only support
115-
// targeting SDK versions by the major version, we'll just look at extracting the major and
116-
// minor versions. This is done by looking for the first two dots in the line.
117-
var firstDot = line.IndexOf('.');
118-
if (firstDot < 0)
119-
continue;
120-
121-
var secondDot = line.IndexOf('.', firstDot + 1);
122-
if (secondDot < 0)
123-
continue;
124-
125-
if (Version.TryParse(line.Substring(0, secondDot), out var version))
114+
// Version.TryParse does not handle things like 3.0.0-WORD, so this will get just the 3.0.0 part
115+
var parsableVersionPart = CoreRuntime.GetParsableVersionPart(line);
116+
if (Version.TryParse(parsableVersionPart, out var version))
126117
{
127118
versions.Add(version);
128119
}

0 commit comments

Comments
 (0)