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

Cannot reference specific version of prerelease #132

Open
avalery opened this issue Jun 17, 2021 · 4 comments · May be fixed by #140
Open

Cannot reference specific version of prerelease #132

avalery opened this issue Jun 17, 2021 · 4 comments · May be fixed by #140

Comments

@avalery
Copy link

avalery commented Jun 17, 2021

Let's stay I published a module named MyModule with a prerelease version 1.2.3-alpha, and tried to use it as a dependency using this configuration:

@{
    'MyModule' = @{
        Name = 'MyModule'
        Version = '1.2.3-alpha'
        Parameters = @{
            AllowPrerelease = $true
        }
    }
}

If I call Invoke-PSDepend "requirements.psd1" -Install -Force -Import to download them and import them automatically, I got an error when PSDepend triggers Import-Module, because it gives "1.2.3-alpha" and Import-Module call only accept "1.2.3".

Isn't possible in PSDepend to adapt the code: if the module is a prerelease, trigger Import-Module with the version number without the prerelease "tag"?

@avalery
Copy link
Author

avalery commented May 25, 2022

Any news about this issue?

@fourpastmidnight
Copy link

I'm looking for this, too. It looks like this has become abandonware. 😢 I have a PR open on another of his modules, BuildHelpers, but crickets.

@fourpastmidnight
Copy link

OK, I tried this using a different configuration. In my case, I was trying to get the updated PowerShellGet module, now called PSResourceGet. Here's the configuration I used:

@{
    PSResourceGet = @{
        Name = 'Microsoft.PowerShell.PSReourceGet'
        DependencyType = 'PSGalleryModule'
        Version = 'latest'
        Parameters = @{
            AllowPrerelease = $true
        }
    }
}

However, it looked like the first time around, all that happened was that the module was "installed" to my specified target path. A subsequent run of PSDepend resulted in an error:

Checking for and installing the latest versions of the build system dependencies...
WARNING: Access to the path 'D:\src\git\MyProject\build\deps\Microsoft.PowerShell.PSResourceGet\0.5.24' is denied.
Save-Package: Unable to save the module 'Microsoft.PowerShell.PSResourceGet'.
Import-Module: C:\Users\me\Documents\PowerShell\Modules\PSDepend\0.3.8\Private\Import-PSDependModule.ps1:21
Line |
  21 |              Import-Module @importParams
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The specified module 'D:\src\git\MyProject\build\deps\Microsoft.PowerShell.PSResourceGet' was not loaded because no valid module
     | file was found in any module directory.

It seems the problem here, is that the Version that is specified in the PSDepend configuration is not updated properly when subsequently passed to Import-Module since the RequiredVersion parameter is of type System.Version, which is a Microsoft-proprietary version number format. PowerShell (at the time this is currently written) really doesn't understand the notion of "pre-release" versions. If you look in the module folder hierarchy, e.g. C:\Users\<you>\Documents\PowerShell\Modules, using PSResourceGet as an example module that only has a pre-release version published:

C:\Users\<you>\Documents\PowerShell\Modules
  └─ Microsoft.PowerShell.PSResourceGet
       └─ 0.5.24
            └─ <other files>

But the real version of this module is 0.5.24-beta24. The way a "pre-release" version of a module is specified is by a metadata field in the module's PSD1 manifest. So, when importing a pre-release module, the pre-release tag must be stripped from the version string.

I'm looking to create a PR for this issue. When I've done so, if @RamblingCookieMonster does not merge this in, you can always clone from my branch. I do this with BuildHelpers currently, as I have an open PR on this module, too, where I added some functionality. Instead of using the PowerShellGet version, I clone my git repo and checkout the branch containing my feature. Just be aware that when using git dependencies, PSDepend can't do an "import" on them because not all git dependencies are PowerShell modules. Too bad there isn't a way to "enable" importing a PowerShell module based on a cloned Git repo....sounds like a custom provider for PSDepend to me! 😉

@fourpastmidnight
Copy link

@avalery In lieu of cloning my git repo, this really is a single-line change. You could just update your copy of the module for now, according to the diff shown in my PR to resolve your issue. Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants