nuget-license icon indicating copy to clipboard operation
nuget-license copied to clipboard

When using Paket the local case has invalid version options

Open michalsteyn opened this issue 1 year ago • 0 comments

When using Paket, the local cache returns invalid versions such as "lib", or "ref" when using the --use-project-assets-json argument.

Here is an example of the error produced:

Reading dependencies for target net8.0
'lib' is not a valid version string. (Parameter 'value')
System.ArgumentException: 'lib' is not a valid version string. (Parameter 'value')
   at NuGet.Versioning.NuGetVersion.Parse(String value)
   at NugetUtility.Methods.<>c.<ResolvePackageVersionAsync>b__15_0(String v) in /home/runner/work/nuget-license/nuget-license/src/Methods.cs:line 235
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at NuGet.Versioning.VersionRange.FindBestMatch(IEnumerable`1 versions)
   at NugetUtility.Methods.GetVersionFromRange(String versionRange, IEnumerable`1 versionList) in /home/runner/work/nuget-license/nuget-license/src/Methods.cs:line 304
   at NugetUtility.Methods.ResolvePackageVersionAsync(String name, String versionRange, Func`2 GetVersions) in /home/runner/work/nuget-license/nuget-license/src/Methods.cs:line 235
   at NugetUtility.Methods.ResolvePackageVersionFromLocalCacheAsync(String name, String versionRange) in /home/runner/work/nuget-license/nuget-license/src/Methods.cs:line 245
   at NugetUtility.Methods.GetNugetInformationAsync(String project, IEnumerable`1 packages) in /home/runner/work/nuget-license/nuget-license/src/Methods.cs:line 118

A very easy and safe way to fix this is to simply check that versions reported by the cache starts with a number.

See the PR: https://github.com/tomchavakis/nuget-license/pull/207

michalsteyn avatar Feb 08 '24 22:02 michalsteyn