Skip to content

Commit

Permalink
Allow to work with semantic versioning (#1259)
Browse files Browse the repository at this point in the history
The VS extension is not able to work with preview versions. If you have a version like 0.27.3-beta, then the extension does not work. This code is fixing this issue. It allows to work with preview versions.

---------

Co-authored-by: Lasath Fernando <[email protected]>
  • Loading branch information
huer12 and shocklateboy92 authored May 20, 2024
1 parent 52cfc11 commit 33a7a00
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ private ICSharpierProcess SetupCSharpierProcess(string directory, string version
var customPath = this.customPathInstaller.GetPathForVersion(version);

this.logger.Debug("Adding new version " + version + " process for " + directory);

var installedVersion = new Version(version);
var installedVersion = GetInstalledVersion(version);
var pipeFilesVersion = new Version("0.12.0");
var serverVersion = new Version("0.28.0");
ICSharpierProcess cSharpierProcess;
Expand Down Expand Up @@ -278,6 +277,27 @@ private ICSharpierProcess SetupCSharpierProcess(string directory, string version
return NullCSharpierProcess.Instance;
}

private Version GetInstalledVersion(string version)
{
if (Version.TryParse(version, out var installedVersion) && installedVersion != null)
{
return installedVersion;
}

// handle semver versions
// regex from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
var regex = Regex.Match(
"0.27.3-dg.13",
@"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
);
if (regex.Success && regex.Groups.Count > 3)
{
return new Version($"{regex.Groups[1]}.{regex.Groups[2]}.{regex.Groups[3]}");
}

throw new ArgumentException($"Unable to parse version '{version}'", nameof(version));
}

private void DisplayFailureMessage()
{
var actionButton = new InfoBarActionButton
Expand Down

0 comments on commit 33a7a00

Please sign in to comment.