diff --git a/src/Methods.cs b/src/Methods.cs index f200855a..9b31812f 100644 --- a/src/Methods.cs +++ b/src/Methods.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Xml.Linq; @@ -231,8 +232,13 @@ private async Task ResolvePackageVersionAsync(string name, string versio return version; } + string versionStartWithNumberPattern = @"^\d"; var versionList = await GetVersions(name); - version = GetVersionFromRange(versionRange, versionList.Select(v => NuGetVersion.Parse(v))); + version = GetVersionFromRange(versionRange, versionList + .Where(v => Regex.IsMatch(v, versionStartWithNumberPattern)) + .Select(ParseNuGetVersion) + .Where(v => v != null)); + if (!string.IsNullOrEmpty(version)) { _versionResolverCache[Tuple.Create(name, versionRange)] = version; @@ -240,6 +246,19 @@ private async Task ResolvePackageVersionAsync(string name, string versio return version; } + private NuGetVersion ParseNuGetVersion(string version) + { + try + { + return NuGetVersion.Parse(version); + } + catch (Exception e) + { + WriteOutput(e.Message, e, LogLevel.Warning); + return null; + } + } + private async Task ResolvePackageVersionFromLocalCacheAsync(string name, string versionRange) { return await ResolvePackageVersionAsync(name, versionRange, GetVersionsFromLocalCacheAsync);