Skip to content

Commit

Permalink
Get full parsable version part (#2646)
Browse files Browse the repository at this point in the history
  • Loading branch information
caaavik-msft authored Sep 24, 2024
1 parent 5fe0c78 commit 52485ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ internal static bool TryGetVersionFromFrameworkName(string frameworkName, out Ve
}

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

private static CoreRuntime GetPlatformSpecific(CoreRuntime fallback)
{
Expand Down
15 changes: 3 additions & 12 deletions src/BenchmarkDotNet/Validators/DotNetSdkVersionValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,9 @@ private static IEnumerable<Version> GetInstalledDotNetSdks(string? customDotNetC
var versions = new List<Version>(lines.Count());
foreach (var line in lines)
{
// Each line will start with the SDK version followed by the SDK path. Since we only support
// targeting SDK versions by the major version, we'll just look at extracting the major and
// minor versions. This is done by looking for the first two dots in the line.
var firstDot = line.IndexOf('.');
if (firstDot < 0)
continue;

var secondDot = line.IndexOf('.', firstDot + 1);
if (secondDot < 0)
continue;

if (Version.TryParse(line.Substring(0, secondDot), out var version))
// Version.TryParse does not handle things like 3.0.0-WORD, so this will get just the 3.0.0 part
var parsableVersionPart = CoreRuntime.GetParsableVersionPart(line);
if (Version.TryParse(parsableVersionPart, out var version))
{
versions.Add(version);
}
Expand Down

0 comments on commit 52485ec

Please sign in to comment.