tomchavakis / nuget-license

.NET Core tool to print or save all the licenses of a project
Apache License 2.0
280 stars 83 forks source link

When using Paket the local case has invalid version options #206

Open michalsteyn opened 9 months ago

michalsteyn commented 9 months ago

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