Deploy PS Module to PSGallery

Marco Blessing's Avatar

Marco Blessing

16 Jan, 2017 10:46 AM

Hi folks,
Is there someone who deploys successfully PowerShell Modules to powershellgallery.com with the PackageManagement Framework?

I'm working on this for about a week now and running always into NuGet errors while using Publish-Module.

Error example: https://ci.appveyor.com/project/OCram85/ponduit/build/1.3.65

I already tried to reinstall the NuGet Package Provider:

Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose
For Details see: https://github.com/OCram85/Ponduit/blob/dev/tools/AppVeyor.psm1#L88

Thanks for your help guys!

  1. 1 Posted by Ilya Finkelshte... on 18 Jan, 2017 04:01 AM

    Ilya Finkelshteyn's Avatar

    Hi Marco,

    Indeed it appears to be an issue you found with WMF5 image you are using. However I see that installing package provider fixes it at least for me.

    This simple YAML works OK

    image: WMF 5
    install:
    - ps: Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose
    build_script:
    - ps: Get-PackageProvider -ListAvailable
    - ps: Get-PackageProvider -Name NuGet
    

    Please try to add this at install stage the same way and let us know if this helped.

    Thanks!
    Ilya.

  2. 2 Posted by Marco Blessing on 18 Jan, 2017 06:44 AM

    Marco Blessing's Avatar

    Hi,
    thanks for the help. Meanwhile I fixed it and came across the same solution you suggested.

    Function Invoke-AppVeyorPSGallery() {
        [CmdletBinding()]
        Param()
        Expand-Archive -Path '.\bin\Ponduit.zip' -DestinationPath 'C:\Users\appveyor\Documents\WindowsPowerShell\Modules\Ponduit\' -Verbose
        Import-Module -Name 'Ponduit' -Verbose -Force
        Write-Host "Available Package Provider:" -ForegroundColor Yellow
        Get-PackageProvider -ListAvailable
        Write-Host "Available Package Sources:" -ForegroundColor Yellow
        Get-PackageSource
        Try {
            Write-Host "Try to get NuGet Provider:" -ForegroundColor Yellow
            Get-PackageProvider -Name NuGet -ErrorAction Stop
        }
        Catch {
            Write-Host "Installing NuGet..." -ForegroundColor Yellow
            Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose
            Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force
        }
        Try {
            If ($env:APPVEYOR_REPO_BRANCH -eq 'master') {
                Write-Host "try to publish module" -ForegroundColor Yellow
                Publish-Module -Name 'Ponduit' -NuGetApiKey $env:NuGetToken -Verbose -Force
            }
            Else {
                Write-Host "Skip publishing to PS Gallery because we are on $($env:APPVEYOR_REPO_BRANCH) branch." -ForegroundColor Yellow
                # had to remve the publish-Module statement bacause it would publish although the -WhatIf is given.
                # Publish-Module -Name 'Ponduit' -NuGetApiKey $env:NuGetToken -Verbose -WhatIf
            }
        }
        Catch {
            $MsgParams = @{
                Message = 'Could not delpoy module to PSGallery.'
                Category = 'Error'
                Details = $_.Exception.Message
            }
            Add-AppveyorMessage @MsgParams
            Throw $MsgParams.Message
        }
    }
    

    Thanks! \//_

  3. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:14 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac