Replace embedded SemanticVersion with NuGet.Versioning package

This commit is contained in:
Caelan Sayler
2022-04-24 09:58:15 +01:00
parent e4894c1690
commit 4d13304699
21 changed files with 73 additions and 394 deletions

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Win32;
using NuGet.Versioning;
using Squirrel.SimpleSplat;
namespace Squirrel

View File

@@ -11,6 +11,7 @@ using Squirrel.SimpleSplat;
using System.Threading.Tasks;
using SharpCompress.Archives.Zip;
using SharpCompress.Readers;
using NuGet.Versioning;
namespace Squirrel
{

View File

@@ -13,6 +13,7 @@ using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net;
using NuGet.Versioning;
namespace Squirrel
{
@@ -505,7 +506,7 @@ namespace Squirrel
public static string AppDirForRelease(string rootAppDirectory, ReleaseEntry entry)
{
return Path.Combine(rootAppDirectory, "app-" + entry.Version.ToString());
return AppDirForVersion(rootAppDirectory, entry.Version);
}
public static string AppDirForVersion(string rootAppDirectory, SemanticVersion version)

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using NuGet.Versioning;
namespace Squirrel.NuGet
{
@@ -28,12 +29,12 @@ namespace Squirrel.NuGet
public static void ThrowIfVersionNotSemverCompliant(string version)
{
if (SemanticVersion.TryParseStrict(version, out var parsed)) {
if (parsed < new SemanticVersion(0, 0, 1, 0)) {
if (SemanticVersion.TryParse(version, out var parsed)) {
if (parsed < new SemanticVersion(0, 0, 1)) {
throw new Exception($"Invalid package version '{version}', it must be >= 0.0.1.");
}
} else {
throw new Exception($"Invalid package version '{version}', it must be a 3-part SemVer compliant version string.");
throw new Exception($"Invalid package version '{version}', it must be a 3-part SemVer2 compliant version string.");
}
}

View File

@@ -1,341 +0,0 @@
using System;
using System.Globalization;
using System.Text.RegularExpressions;
namespace Squirrel
{
/// <summary>
/// A hybrid implementation of SemVer that supports semantic versioning as described at http://semver.org while not strictly enforcing it to
/// allow older 4-digit versioning schemes to continue working.
/// </summary>
[Serializable]
public sealed class SemanticVersion : IComparable, IComparable<SemanticVersion>, IEquatable<SemanticVersion>
{
private const RegexOptions _flags = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture;
private static readonly Regex _semanticVersionRegex = new Regex(@"^(?<Version>\d+(\s*\.\s*\d+){0,3})(?<Release>-[a-z][0-9a-z-]*)?$", _flags);
private static readonly Regex _strictSemanticVersionRegex = new Regex(@"^(?<Version>\d+(\.\d+){2})(?<Release>-[a-z][0-9a-z-]*)?$", _flags);
private static readonly Regex _preReleaseVersionRegex = new Regex(@"(?<PreReleaseString>[a-z]+)(?<PreReleaseNumber>[0-9]+)$", _flags);
private readonly string _originalString;
/// <summary> Create a new instance of <see cref="SemanticVersion"/> with the specified version </summary>
public SemanticVersion(string version)
: this(Parse(version))
{
// The constructor normalizes the version string so that it we do not need to normalize it every time we need to operate on it.
// The original string represents the original form in which the version is represented to be used when printing.
_originalString = version;
}
/// <inheritdoc cref="SemanticVersion(string)"/>
public SemanticVersion(int major, int minor, int build)
: this(new Version(major, minor, build, 0))
{
}
/// <inheritdoc cref="SemanticVersion(string)"/>
public SemanticVersion(int major, int minor, int build, int revision)
: this(new Version(major, minor, build, revision))
{
}
/// <inheritdoc cref="SemanticVersion(string)"/>
public SemanticVersion(int major, int minor, int build, string specialVersion)
: this(new Version(major, minor, build), specialVersion)
{
}
/// <inheritdoc cref="SemanticVersion(string)"/>
public SemanticVersion(Version version)
: this(version, String.Empty)
{
}
/// <inheritdoc cref="SemanticVersion(string)"/>
public SemanticVersion(Version version, string specialVersion)
: this(version, specialVersion, null)
{
}
private SemanticVersion(Version version, string specialVersion, string originalString)
{
if (version == null) {
throw new ArgumentNullException("version");
}
Version = NormalizeVersionValue(version);
SpecialVersion = specialVersion ?? String.Empty;
_originalString = String.IsNullOrEmpty(originalString) ? version.ToString() + (!String.IsNullOrEmpty(specialVersion) ? '-' + specialVersion : null) : originalString;
}
internal SemanticVersion(SemanticVersion semVer)
{
_originalString = semVer.ToString();
Version = semVer.Version;
SpecialVersion = semVer.SpecialVersion;
}
/// <summary> Gets the value of the major component of the version number for the current System.Version object. </summary>
public int Major => Version.Major;
/// <summary> Gets the value of the minor component of the version number for the current System.Version object. </summary>
public int Minor => Version.Minor;
/// <summary> Gets the value of the build component of the version number for the current System.Version object. </summary>
public int Build => Version.Build;
/// <summary> Gets the value of the revision component of the version number for the current System.Version object. </summary>
public int Revision => Version.Revision;
/// <summary>
/// Gets the normalized version portion.
/// </summary>
public Version Version {
get;
private set;
}
/// <summary>
/// Gets the optional special version.
/// </summary>
public string SpecialVersion {
get;
private set;
}
/// <summary>
/// Gets the components of the original string used to construct this version instance.
/// </summary>
public string[] GetOriginalVersionComponents()
{
if (!String.IsNullOrEmpty(_originalString)) {
string original;
// search the start of the SpecialVersion part, if any
int dashIndex = _originalString.IndexOf('-');
if (dashIndex != -1) {
// remove the SpecialVersion part
original = _originalString.Substring(0, dashIndex);
} else {
original = _originalString;
}
return SplitAndPadVersionString(original);
} else {
return SplitAndPadVersionString(Version.ToString());
}
}
private static string[] SplitAndPadVersionString(string version)
{
string[] a = version.Split('.');
if (a.Length == 4) {
return a;
} else {
// if 'a' has less than 4 elements, we pad the '0' at the end
// to make it 4.
var b = new string[4] { "0", "0", "0", "0" };
Array.Copy(a, 0, b, 0, a.Length);
return b;
}
}
/// <summary>
/// Parses a version string using loose semantic versioning rules that allows 2-4 version components followed by an optional special version.
/// </summary>
public static SemanticVersion Parse(string version)
{
if (String.IsNullOrEmpty(version)) {
throw new ArgumentException("Argument_Cannot_Be_Null_Or_Empty", "version");
}
SemanticVersion semVer;
if (!TryParse(version, out semVer)) {
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "InvalidVersionString", version), "version");
}
return semVer;
}
/// <summary>
/// Parses a version string using loose semantic versioning rules that allows 2-4 version components followed by an optional special version.
/// </summary>
public static bool TryParse(string version, out SemanticVersion value)
{
return TryParseInternal(version, _semanticVersionRegex, out value);
}
/// <summary>
/// Parses a version string using strict semantic versioning rules that allows exactly 3 components and an optional special version.
/// </summary>
public static bool TryParseStrict(string version, out SemanticVersion value)
{
return TryParseInternal(version, _strictSemanticVersionRegex, out value);
}
private static bool TryParseInternal(string version, Regex regex, out SemanticVersion semVer)
{
semVer = null;
if (String.IsNullOrEmpty(version)) {
return false;
}
var match = regex.Match(version.Trim());
Version versionValue;
if (!match.Success || !Version.TryParse(match.Groups["Version"].Value, out versionValue)) {
return false;
}
semVer = new SemanticVersion(NormalizeVersionValue(versionValue), match.Groups["Release"].Value.TrimStart('-'), version.Replace(" ", ""));
return true;
}
/// <summary>
/// Attempts to parse the version token as a SemanticVersion.
/// </summary>
/// <returns>An instance of SemanticVersion if it parses correctly, null otherwise.</returns>
public static SemanticVersion ParseOptionalVersion(string version)
{
SemanticVersion semVer;
TryParse(version, out semVer);
return semVer;
}
private static Version NormalizeVersionValue(Version version)
{
return new Version(version.Major,
version.Minor,
Math.Max(version.Build, 0),
Math.Max(version.Revision, 0));
}
/// <inheritdoc/>
public int CompareTo(object obj)
{
if (Object.ReferenceEquals(obj, null)) {
return 1;
}
SemanticVersion other = obj as SemanticVersion;
if (other == null) {
throw new ArgumentException("TypeMustBeASemanticVersion", "obj");
}
return CompareTo(other);
}
/// <inheritdoc/>
public int CompareTo(SemanticVersion other)
{
if (Object.ReferenceEquals(other, null)) {
return 1;
}
int result = Version.CompareTo(other.Version);
if (result != 0) {
return result;
}
bool empty = String.IsNullOrEmpty(SpecialVersion);
bool otherEmpty = String.IsNullOrEmpty(other.SpecialVersion);
if (empty && otherEmpty) {
return 0;
} else if (empty) {
return 1;
} else if (otherEmpty) {
return -1;
}
// If both versions have a prerelease section with the same prefix
// and end with digits, compare based on the digits' numeric order
var match = _preReleaseVersionRegex.Match(SpecialVersion.Trim());
var otherMatch = _preReleaseVersionRegex.Match(other.SpecialVersion.Trim());
if (match.Success && otherMatch.Success &&
string.Equals(
match.Groups["PreReleaseString"].Value,
otherMatch.Groups["PreReleaseString"].Value,
StringComparison.OrdinalIgnoreCase)) {
int delta =
int.Parse(match.Groups["PreReleaseNumber"].Value) -
int.Parse(otherMatch.Groups["PreReleaseNumber"].Value);
return delta != 0 ? delta / Math.Abs(delta) : 0;
}
return StringComparer.OrdinalIgnoreCase.Compare(SpecialVersion, other.SpecialVersion);
}
/// <inheritdoc/>
public static bool operator ==(SemanticVersion version1, SemanticVersion version2)
{
if (Object.ReferenceEquals(version1, null)) {
return Object.ReferenceEquals(version2, null);
}
return version1.Equals(version2);
}
/// <inheritdoc/>
public static bool operator !=(SemanticVersion version1, SemanticVersion version2)
{
return !(version1 == version2);
}
/// <inheritdoc/>
public static bool operator <(SemanticVersion version1, SemanticVersion version2)
{
if (version1 == null) {
throw new ArgumentNullException("version1");
}
return version1.CompareTo(version2) < 0;
}
/// <inheritdoc/>
public static bool operator <=(SemanticVersion version1, SemanticVersion version2)
{
return (version1 == version2) || (version1 < version2);
}
/// <inheritdoc/>
public static bool operator >(SemanticVersion version1, SemanticVersion version2)
{
if (version1 == null) {
throw new ArgumentNullException("version1");
}
return version2 < version1;
}
/// <inheritdoc/>
public static bool operator >=(SemanticVersion version1, SemanticVersion version2)
{
return (version1 == version2) || (version1 > version2);
}
/// <inheritdoc/>
public override string ToString()
{
return _originalString;
}
/// <inheritdoc/>
public bool Equals(SemanticVersion other)
{
return !Object.ReferenceEquals(null, other) &&
Version.Equals(other.Version) &&
SpecialVersion.Equals(other.SpecialVersion, StringComparison.OrdinalIgnoreCase);
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
SemanticVersion semVer = obj as SemanticVersion;
return !Object.ReferenceEquals(null, semVer) && Equals(semVer);
}
/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = Version.GetHashCode();
if (SpecialVersion != null) {
hashCode = hashCode * 4567 + SpecialVersion.GetHashCode();
}
return hashCode;
}
}
}

View File

@@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using NuGet.Versioning;
using SharpCompress.Archives.Zip;
namespace Squirrel.NuGet
@@ -200,7 +201,7 @@ namespace Squirrel.NuGet
Id = value;
break;
case "version":
Version = new SemanticVersion(value);
Version = NuGetVersion.Parse(value);
break;
case "authors":
Authors = getCommaDelimitedValue(value);

View File

@@ -10,6 +10,7 @@ using Squirrel.SimpleSplat;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using NuGet.Versioning;
namespace Squirrel
{
@@ -408,7 +409,7 @@ namespace Squirrel
var name = nameAndVer.Substring(0, verIdx);
var version = nameAndVer.Substring(verIdx + 1);
var semVer = new SemanticVersion(version);
var semVer = NuGetVersion.Parse(version);
return (name, semVer, delta);
}
}

View File

@@ -9,6 +9,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32;
using NuGet.Versioning;
using Squirrel.SimpleSplat;
using Squirrel.Sources;
@@ -166,7 +167,7 @@ namespace Squirrel
: $".NET Core {TrimVersion(MinVersion)} Desktop Runtime ({CpuArchitecture.ToString().ToLower()})";
/// <summary> The minimum compatible version that must be installed. </summary>
public SemanticVersion MinVersion { get; }
public NuGetVersion MinVersion { get; }
/// <summary> The CPU architecture of the runtime. This must match the RID of the app being deployed.
/// For example, if the Squirrel app was deployed with 'win-x64', this must be X64 also. </summary>
@@ -175,14 +176,14 @@ namespace Squirrel
/// <inheritdoc/>
protected DotnetInfo(Version minversion, RuntimeCpu architecture)
{
MinVersion = new SemanticVersion(minversion);
MinVersion = new NuGetVersion(minversion);
CpuArchitecture = architecture;
if (minversion.Major == 6 && minversion.Build < 0) {
Log.Warn(
$"Automatically upgrading minimum dotnet version from net{minversion} to net6.0.2, " +
$"see more at https://github.com/dotnet/core/issues/7176. " +
$"If you would like to stop this behavior, please specify '--framework net6.0.0'");
MinVersion = new SemanticVersion(6, 0, 2);
MinVersion = new NuGetVersion(6, 0, 2);
}
}
@@ -254,8 +255,8 @@ namespace Squirrel
var dirs = Directory.EnumerateDirectories(directory)
.Select(d => Path.GetFileName(d))
.Where(d => SemanticVersion.TryParse(d, out var _))
.Select(d => SemanticVersion.Parse(d));
.Where(d => NuGetVersion.TryParse(d, out var _))
.Select(d => NuGetVersion.Parse(d));
return dirs.Any(v => v.Major == MinVersion.Major && v.Minor == MinVersion.Minor && v >= MinVersion);
}
@@ -337,14 +338,14 @@ namespace Squirrel
/// <summary>
/// Converts a version structure into the shortest string possible, by trimming trailing zeros.
/// </summary>
protected static string TrimVersion(SemanticVersion ver)
protected static string TrimVersion(NuGetVersion ver)
{
string v = ver.Major.ToString();
if (ver.Minor > 0 || ver.Build > 0 || ver.Revision > 0) {
if (ver.Minor > 0 || ver.Patch > 0 || ver.Revision > 0) {
v += "." + ver.Minor;
}
if (ver.Build > 0 || ver.Revision > 0) {
v += "." + ver.Build;
if (ver.Patch > 0 || ver.Revision > 0) {
v += "." + ver.Patch;
}
if (ver.Revision > 0) {
v += "." + ver.Revision;
@@ -402,13 +403,13 @@ namespace Squirrel
public abstract class VCRedistInfo : RuntimeInfo
{
/// <summary> The minimum compatible version that must be installed. </summary>
public SemanticVersion MinVersion { get; }
public NuGetVersion MinVersion { get; }
/// <summary> The CPU architecture of the runtime. </summary>
public RuntimeCpu CpuArchitecture { get; }
/// <inheritdoc/>
public VCRedistInfo(string id, string displayName, SemanticVersion minVersion, RuntimeCpu cpuArchitecture) : base(id, displayName)
public VCRedistInfo(string id, string displayName, NuGetVersion minVersion, RuntimeCpu cpuArchitecture) : base(id, displayName)
{
MinVersion = minVersion;
CpuArchitecture = cpuArchitecture;
@@ -439,9 +440,9 @@ namespace Squirrel
/// Returns the list of currently installed VC++ redistributables, as reported by the
/// Windows Programs &amp; Features dialog.
/// </summary>
public static (SemanticVersion Ver, RuntimeCpu Cpu)[] GetInstalledVCVersions()
public static (NuGetVersion Ver, RuntimeCpu Cpu)[] GetInstalledVCVersions()
{
List<(SemanticVersion Ver, RuntimeCpu Cpu)> results = new List<(SemanticVersion Ver, RuntimeCpu Cpu)>();
List<(NuGetVersion Ver, RuntimeCpu Cpu)> results = new List<(NuGetVersion Ver, RuntimeCpu Cpu)>();
void searchreg(RegistryKey view)
{
@@ -450,7 +451,7 @@ namespace Squirrel
var name = subKey.GetValue("DisplayName") as string;
if (name != null && name.Contains("Microsoft Visual C++") && name.Contains("Redistributable")) {
var version = subKey.GetValue("DisplayVersion") as string;
if (SemanticVersion.TryParse(version, out var v)) {
if (NuGetVersion.TryParse(version, out var v)) {
// these entries do not get added into the correct registry hive, so we need to determine
// the cpu architecture from the name. I hate this but what can I do?
if (name.Contains("x64") && Environment.Is64BitOperatingSystem) {
@@ -481,7 +482,7 @@ namespace Squirrel
public class VCRedist14 : VCRedistInfo
{
/// <inheritdoc/>
public VCRedist14(string id, string displayName, SemanticVersion minVersion, RuntimeCpu cpuArchitecture)
public VCRedist14(string id, string displayName, NuGetVersion minVersion, RuntimeCpu cpuArchitecture)
: base(id, displayName, minVersion, cpuArchitecture)
{
}
@@ -507,7 +508,7 @@ namespace Squirrel
public string DownloadUrl { get; }
/// <inheritdoc/>
public VCRedist00(string id, string displayName, SemanticVersion minVersion, RuntimeCpu cpuArchitecture, string downloadUrl)
public VCRedist00(string id, string displayName, NuGetVersion minVersion, RuntimeCpu cpuArchitecture, string downloadUrl)
: base(id, displayName, minVersion, cpuArchitecture)
{
DownloadUrl = downloadUrl;

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NuGet.Versioning;
using Squirrel.SimpleSplat;
namespace Squirrel
@@ -138,7 +139,7 @@ namespace Squirrel
Log.ErrorException($"Unable to verify version for runtime '{f}'", ex);
}
if (latest != null && SemanticVersion.Parse(latest) < dni.MinVersion) {
if (latest != null && NuGetVersion.Parse(latest) < dni.MinVersion) {
throw new Exception($"For runtime string '{f}', version provided ({dni.MinVersion}) is greater than the latest available version ({latest}).");
}
}

View File

@@ -16,6 +16,7 @@
<ItemGroup>
<PackageReference Include="SharpCompress" Version="0.31.0" />
<PackageReference Include="NuGet.Versioning" Version="6.1.0" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'net5.0' ">

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using NuGet.Versioning;
using Squirrel.SimpleSplat;
namespace Squirrel
@@ -81,7 +82,7 @@ namespace Squirrel
// in the fastExitLookup arguments, we run the squirrel hook and then exit the process
if (args.Length >= 2 && fastExitlookup.ContainsKey(args[0])) {
var version = new SemanticVersion(args[1]);
var version = NuGetVersion.Parse(args[1]);
try {
fastExitlookup[args[0]](version, um);
if (!ModeDetector.InUnitTestRunner()) Environment.Exit(0);

View File

@@ -12,6 +12,7 @@ using Squirrel.SimpleSplat;
using System.Threading;
using Squirrel.Shell;
using Microsoft.Win32;
using NuGet.Versioning;
namespace Squirrel
{
@@ -133,7 +134,7 @@ namespace Squirrel
}
try {
this.ErrorIfThrows(() => fixPinnedExecutables(new SemanticVersion(255, 255, 255, 255), true));
this.ErrorIfThrows(() => fixPinnedExecutables(new SemanticVersion(255, 255, 255), true));
} catch { }
this.ErrorIfThrows(() => Utility.DeleteFileOrDirectoryHardOrGiveUp(rootAppDirectory),
@@ -680,7 +681,7 @@ namespace Squirrel
return rootDirectory.GetDirectories()
.Where(x => x.Name.StartsWith("app-", StringComparison.InvariantCultureIgnoreCase))
.Select(x => (x, new SemanticVersion(x.Name.Substring(4))));
.Select(x => (x, (SemanticVersion)NuGetVersion.Parse(x.Name.Substring(4))));
}
DirectoryInfo getDirectoryForRelease(SemanticVersion releaseVersion)

View File

@@ -11,6 +11,7 @@ using Squirrel.NuGet;
using Squirrel.SimpleSplat;
using Squirrel.Shell;
using Squirrel.Sources;
using NuGet.Versioning;
namespace Squirrel
{
@@ -211,7 +212,7 @@ namespace Squirrel
if (appDirName == null)
return null;
return new SemanticVersion(appDirName.Substring(4));
return NuGetVersion.Parse(appDirName.Substring(4));
}
/// <inheritdoc/>

View File

@@ -3,6 +3,7 @@
using Microsoft.NET.HostModel.AppHost;
using Microsoft.NET.HostModel.Bundle;
using NuGet.Versioning;
using Squirrel;
using Squirrel.SimpleSplat;
using System;
@@ -103,7 +104,7 @@ namespace SquirrelCli
}
foreach (var f in lookup) {
var fver = new SemanticVersion(f.Value.MajorVersion, f.Value.MinorVersion, f.Value.BuildNumber, f.Value.RevisionNumber);
var fver = new NuGetVersion(f.Value.MajorVersion, f.Value.MinorVersion, f.Value.BuildNumber, f.Value.RevisionNumber);
if (fver > runtime.MinVersion) {
Log.Warn($"{name} references {f.Key},Version={fver} - which is higher than the current runtime version ({runtime.MinVersion}).");
}

View File

@@ -14,6 +14,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Mono.Options;
using NuGet.Versioning;
using Squirrel;
using Squirrel.Json;
using Squirrel.Lib;
@@ -243,7 +244,7 @@ namespace SquirrelCli
// warning if the installed SquirrelLib version is not the same as Squirrel.exe
StringFileInfo sqLib = null;
try {
var myFileVersion = new SemanticVersion(FileVersion).Version;
var myFileVersion = new NuGetVersion(FileVersion).Version;
sqLib = Directory.EnumerateFiles(libDir, "SquirrelLib.dll")
.Select(f => { StringFileInfo.ReadVersionInfo(f, out var fi); return fi; })
.FirstOrDefault(fi => fi.FileVersion != myFileVersion);
@@ -414,7 +415,7 @@ namespace SquirrelCli
{ "Id", wixId },
{ "Title", package.ProductName },
{ "Author", package.ProductCompany },
{ "Version", package.Version.Version.ToString() },
{ "Version", $"{package.Version.Major}.{package.Version.Minor}.{package.Version.Patch}.0" },
{ "Summary", package.ProductDescription },
{ "Codepage", $"{culture}" },
{ "Platform", packageAs64Bit ? "x64" : "x86" },

View File

@@ -15,6 +15,7 @@ using System.Threading.Tasks;
using Squirrel.NuGet;
using Squirrel.Lib;
using static Squirrel.Runtimes.RuntimeInstallResult;
using NuGet.Versioning;
namespace Squirrel.Update
{
@@ -484,7 +485,7 @@ namespace Squirrel.Update
.OrderByDescending(x => x.Version)
.SelectMany(x => new[] {
Utility.AppDirForRelease(appDir, x),
Utility.AppDirForVersion(appDir, new SemanticVersion(x.Version.Version.Major, x.Version.Version.Minor, x.Version.Version.Build, ""))
Utility.AppDirForVersion(appDir, new SemanticVersion(x.Version.Major, x.Version.Minor, x.Version.Patch, ""))
})
.FirstOrDefault(x => Directory.Exists(x));

View File

@@ -8,6 +8,7 @@ using Squirrel.SimpleSplat;
using Squirrel.Tests.TestHelpers;
using Xunit;
using Xunit.Abstractions;
using NuGet.Versioning;
namespace Squirrel.Tests
{
@@ -67,7 +68,7 @@ namespace Squirrel.Tests
var result = new ZipPackage(outFile);
result.Id.ShouldEqual("slack");
result.Version.ShouldEqual(new SemanticVersion("1.2.0"));
result.Version.ShouldEqual(SemanticVersion.Parse("1.2.0"));
} finally {
if (File.Exists(outFile)) {
File.Delete(outFile);

View File

@@ -5,6 +5,7 @@ using Squirrel;
using Squirrel.Tests.TestHelpers;
using Xunit;
using Squirrel.NuGet;
using NuGet.Versioning;
namespace Squirrel.Tests
{
@@ -104,7 +105,7 @@ namespace Squirrel.Tests
{
var fixture = ReleaseEntry.ParseReleaseEntry(releaseEntry);
Assert.Equal(new SemanticVersion(new Version(major, minor, patch, revision), prerelease), fixture.Version);
Assert.Equal(new NuGetVersion(major, minor, patch, revision, prerelease, null), fixture.Version);
Assert.Equal(isDelta, fixture.IsDelta);
}
@@ -142,7 +143,7 @@ namespace Squirrel.Tests
{
var fixture = ReleaseEntry.ParseReleaseEntry(releaseEntry);
Assert.Equal(new SemanticVersion(new Version(major, minor, patch, revision), prerelease), fixture.Version);
Assert.Equal(new NuGetVersion(major, minor, patch, revision, prerelease, null), fixture.Version);
Assert.Equal(isDelta, fixture.IsDelta);
if (stagingPercentage.HasValue) {
@@ -198,7 +199,7 @@ namespace Squirrel.Tests
[Fact]
public void WhenMultipleReleaseMatchesReturnEarlierResult()
{
var expected = new SemanticVersion("1.7.5-beta");
var expected = SemanticVersion.Parse("1.7.5-beta");
var package = new ReleasePackage("Espera-1.7.6-beta.nupkg");
var releaseEntries = new[] {
@@ -217,7 +218,7 @@ namespace Squirrel.Tests
[Fact]
public void WhenMultipleReleasesFoundReturnPreviousVersion()
{
var expected = new SemanticVersion("1.7.6-beta");
var expected = SemanticVersion.Parse("1.7.6-beta");
var input = new ReleasePackage("Espera-1.7.7-beta.nupkg");
var releaseEntries = new[] {
@@ -236,7 +237,7 @@ namespace Squirrel.Tests
[Fact]
public void WhenMultipleReleasesFoundInOtherOrderReturnPreviousVersion()
{
var expected = new SemanticVersion("1.7.6-beta");
var expected = SemanticVersion.Parse("1.7.6-beta");
var input = new ReleasePackage("Espera-1.7.7-beta.nupkg");
var releaseEntries = new[] {
@@ -256,9 +257,9 @@ namespace Squirrel.Tests
public void WhenReleasesAreOutOfOrderSortByVersion()
{
var path = Path.GetTempFileName();
var firstVersion = new SemanticVersion("1.0.0");
var secondVersion = new SemanticVersion("1.1.0");
var thirdVersion = new SemanticVersion("1.2.0");
var firstVersion = SemanticVersion.Parse("1.0.0");
var secondVersion = SemanticVersion.Parse("1.1.0");
var thirdVersion = SemanticVersion.Parse("1.2.0");
var releaseEntries = new[] {
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-delta.nupkg")),
@@ -284,20 +285,20 @@ namespace Squirrel.Tests
}
[Fact]
public void WhenPreReleasesAreOutOfOrderSortByNumericSuffix()
public void WhenPreReleasesAreOutOfOrderSortByNumericSuffixSemVer2()
{
var path = Path.GetTempFileName();
var firstVersion = new SemanticVersion("1.1.9-beta105");
var secondVersion = new SemanticVersion("1.2.0-beta9");
var thirdVersion = new SemanticVersion("1.2.0-beta10");
var fourthVersion = new SemanticVersion("1.2.0-beta100");
var firstVersion = SemanticVersion.Parse("1.1.9-beta.105");
var secondVersion = SemanticVersion.Parse("1.2.0-beta.9");
var thirdVersion = SemanticVersion.Parse("1.2.0-beta.10");
var fourthVersion = SemanticVersion.Parse("1.2.0-beta.100");
var releaseEntries = new[] {
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-beta1-full.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-beta9-full.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-beta100-full.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.1.9-beta105-full.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-beta10-full.nupkg"))
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-beta.1-full.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-beta.9-full.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-beta.100-full.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.1.9-beta.105-full.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.2.0-beta.10-full.nupkg"))
};
ReleaseEntry.WriteReleaseFile(releaseEntries, path);

View File

@@ -12,6 +12,7 @@ using Squirrel.SimpleSplat;
using Xunit;
using Squirrel.NuGet;
using Xunit.Abstractions;
using NuGet.Versioning;
namespace Squirrel.Tests
{
@@ -30,7 +31,7 @@ namespace Squirrel.Tests
public void SemanticVersionParsesValidVersion(string ver)
{
NugetUtil.ThrowIfVersionNotSemverCompliant(ver);
Assert.True(SemanticVersion.TryParseStrict(ver, out var _));
Assert.True(SemanticVersion.TryParse(ver, out var _));
}
[Theory]

View File

@@ -12,6 +12,7 @@ using Xunit;
using System.Net;
using Squirrel.NuGet;
using System.Net.Http;
using NuGet.Versioning;
namespace Squirrel.Tests
{
@@ -326,7 +327,7 @@ namespace Squirrel.Tests
Assert.Null(fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "app.exe")));
Assert.Null(fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "theApp", "app.exe")));
Assert.Null(fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "theApp", "wrongDir", "app.exe")));
Assert.Equal(new SemanticVersion(1, 0, 1, 9), fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "theApp", "app-1.0.1.9", "app.exe")));
Assert.Equal(new SemanticVersion(1, 0, 9), fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "theApp", "app-1.0.9", "app.exe")));
}
}
}

View File

@@ -5,6 +5,7 @@ using System.IO.Packaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NuGet.Versioning;
using Squirrel.NuGet;
using Squirrel.Tests.TestHelpers;
using Xunit;
@@ -48,7 +49,7 @@ namespace Squirrel.Tests
var dyn = ExposedObject.From(zp);
Assert.Equal("FullNuspec", zp.Id);
Assert.Equal(new SemanticVersion("1.0"), zp.Version);
Assert.Equal(SemanticVersion.Parse("1.0.0"), zp.Version);
Assert.Equal(new[] { "Anaïs Betts", "Caelan Sayler" }, dyn.Authors);
Assert.Equal(new Uri("https://github.com/clowd/Clowd.Squirrel"), zp.ProjectUrl);
Assert.Equal(new Uri("https://user-images.githubusercontent.com/1287295/131249078-9e131e51-0b66-4dc7-8c0a-99cbea6bcf80.png"), zp.IconUrl);