RamblingCookieMonster / PSDepend

PowerShell Dependency Handler
MIT License
285 stars 76 forks source link

Error Parsing Version string with nugetrepo #66

Closed sheldonhull closed 5 years ago

sheldonhull commented 6 years ago
    Humanizer                              = @{
        Name           = 'Humanizer'
        Source         = 'nugetrepo'
        DependencyType = 'Package'
        MinimumVersion = '3.11'
        Target         = 'C:\packages'
        DependsOn      = 'EnsureNugetRepositoryRegistered'
        Parameters     = @{
            ProviderName = 'nuget'
        }
    }

Using this statement to download a nuget package via nuget.exe provides an error that cannot convert double to version. This had been working until lately, so perhaps so version parsing method changed?

I'm currently using PSDepend version: 0.1.62

pshamus commented 5 years ago

I just ran into this as well with a module from the PSGallery with just a major.minor version. Note that it only happens with the module has already been downloaded and PSDepend is doing a compare against the gallery. The issue stems from this code:

https://github.com/RamblingCookieMonster/PSDepend/blob/f514c3600546e4422c1a1d1c406254eb5f27a585/PSDepend/PSDependScripts/PSGalleryModule.ps1#L199

Running that line returns the following:

Find-Module -Name $Name -Repository $Repository | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum
0.3

This compared to what is returned with the existing module:

$Existing | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum
Major  Minor  Build  Revision
-----  -----  -----  --------
0      3      -1     -1

I'm wondering if the bug should be raised here or with PowerShellGet?

The only thing I can think of is to cast the output from Find-Module to System.Version. Not sure what that might break, though.

tlindsay42 commented 5 years ago

Just ran into this on a revived project:

Could not compare "2.2" to "2.0.0". Error: "Cannot convert the "2.0.0" value of type "System.Version" to type "System.Double"."
At C:\Users\appveyor\Documents\WindowsPowerShell\Modules\PSDepend\0.3.0\PSDependScripts\PSGalleryModule.ps1:198 char:10
+         ($GalleryVersion = (& $GetGalleryVersion)) -le $ExistingVersi ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : ComparisonFailure

Could not compare "2.2" to "2.2". Error: "Cannot convert the "2.2" value of type "System.Version" to type "System.Double"."
At C:\Users\appveyor\Documents\WindowsPowerShell\Modules\PSDepend\0.3.0\PSDependScripts\PSGalleryModule.ps1:198 char:10
+         ($GalleryVersion = (& $GetGalleryVersion)) -le $ExistingVersi ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : ComparisonFailure```

https://ci.appveyor.com/project/tlindsay42/armorpowershell/build/job/sh0m0u5jm13c267o#L62

https://travis-ci.org/tlindsay42/ArmorPowerShell/jobs/556512385#L582

matt2005 commented 5 years ago

This error happens when using psdepent 0.3.0. The below was workign until yesterday when MS pushed a new version of powershellget but the new version is 2.2 instead of being 2.2.0.

ERROR: Could not compare "2.2" to "2.2". Error: "Cannot convert the "2.2" value of type "System.Version" to type "System.Double"."

    'PowerShellGet'                      = @{
        DependencyType = 'PSGalleryModule'
        Parameters     = @{
            Repository = 'PSGallery'
        }
    }