Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove invalid NuGet Versions reported by the local cache. #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -231,15 +232,33 @@ private async Task<string> 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;
}
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<string> ResolvePackageVersionFromLocalCacheAsync(string name, string versionRange)
{
return await ResolvePackageVersionAsync(name, versionRange, GetVersionsFromLocalCacheAsync);
Expand Down