PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
476 stars 90 forks source link

Save-PSResource doesn't install the correct version. #1657

Open ADD-Izan-Garcia opened 1 month ago

ADD-Izan-Garcia commented 1 month ago

Prerequisites

Steps to reproduce

I am experiencing a problem with Save-PSResource. When installing a specific version of a module from a NuGet server, it doesn't take the one specified. Steps to reproduce:

  1. Have one powershell module in a NuGet server with two different versions published, like '2024.5.20.1' and 2024.5.20.12'
  2. Download the module with the cmdlet:
    Save-PSResource -Name ExampleModule -Version [2024.5.20.1] -Repository ExampleRepository -Path  C:\Users\ExampleUser\Documents -SkipDependencyCheck

Expected behavior

ExampleModule installed in:
C:\Users\ExampleUser\Documents\ExampleModule\2024.5.20.1\ExampleModule.psd1
C:\Users\ExampleUser\Documents\ExampleModule\2024.5.20.1\ExampleModule.psm1 

Inside the ExampleModule.psd1, the field ModuleVersion with the correct version, in this case '2024.5.20.1'

Actual behavior

ExampleModule installed in:
C:\Users\ExampleUser\Documents\ExampleModule\2024.5.20.1\ExampleModule.psd1
C:\Users\ExampleUser\Documents\ExampleModule\2024.5.20.1\ExampleModule.psm1 

Inside the ExampleModule.psd1, the field ModuleVersion with an incorrect version, in this case '2024.5.20.12'

Error details

No response

Environment data

PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Microsoft Windows 10.0.20348
Platfor Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0....}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Visuals

No response

237dmitry commented 1 month ago

I could not reproduce:

$ Save-PSResource -Name PSWSMan -Version 2.3.0 -Path ./Downloads/ -IncludeXml
$ tree -d ./Downloads/PSWSMan/
./Downloads/PSWSMan/
└── 2.3.0
    ├── bin
    │   ├── glibc-1.0
    │   ├── glibc-1.1
    │   ├── glibc-3
    │   ├── macOS-1.1
    │   ├── macOS-3
    │   ├── musl-1.1
    │   └── musl-3
    └── en-US
ADD-Izan-Garcia commented 1 month ago

Its not the same scenario. I think the problem is that instead of taking the version '2024.5.20.1' as exact version, is taking it as minimum version. That's why then the version '2024.5.20.12' is taken.

237dmitry commented 1 month ago

Its not the same scenario.

A did not find modules with similar versions:

$ Save-PSResource -Name PSWriteColor -Version 0.7 -Path ./Downloads/ -IncludeXml
$ Save-PSResource -Name PSWriteColor -Version 0.71 -Path ./Downloads/ -IncludeXml
$ (dir ./Downloads/PSWriteColor/).Name
0.7
0.71
mklement0 commented 1 month ago

I also cannot reproduce the problem, at least with the PSWriteColor module.

The -Version parameter is explicitly documented as being version-exact (no need for [...] enclosure), and that to get the minimum-compatible-version behavior you'd have to use something like '[1.0.0,]' (note the comma).

mklement0 commented 1 month ago

On second thought:

I wonder if the problem is related to that, and how such invalid-as-semver version numbers are de facto / should be handled.