1 minute read

I arrived at the steps below after some trial and error. At the time this writing (04/17/2023) there seems to be some incompatibility with the default version of PowerShellGet and the version of NuGet server that powers GitHub Packages.

As a workaround to these incompatibilities, my approach is as follows:

  • Set up the NuGet client to read packages from private GitHub Packages registry
  • Create a local PowerShell Module Registry
  • Using the NuGet client, download the module package directly to local PowerShell Module Registry
  • Install the package from local PowerShell Module Registry

Note that publishing a PowerShell module to GitHub Packages is discussed in a previous post.

jobs:
    publish:
        runs-on: ubuntu-latest
        permissions:
          actions: read
          packages: write
        steps:
          - uses: nuget/setup-nuget@v1
            with:
              nuget-version: '5.x'
          - name: Add private Nuget source
            shell: pwsh
            run: |-
              $user = "${{ github.actor }}"
              $token = "${{ env.nugetSourceKey }}"
              $feed = "${{ env.nugetSourceUrl }}"
              $packageSourceName = "PrivateNugetSource"

              ## Add the package source
              nuget sources add `
                -Name $packageSourceName `
                -UserName $user `
                -Password $token `
                -Source $feed `
                -Verbosity detailed `
                -StorePasswordInClearText

              ## Set the API key
              nuget setapikey $token -Source $feed

              ## Create a directory for local repository
              mkdir ./__modules

              ## Register the local repository
              Register-PSRepository `
                -Name 'localRepository' `
                -SourceLocation ./__modules `
                -InstallationPolicy Trusted 

          - name: Install PowerShell module
            shell: pwsh
            run: |-

              ## Install the package containing the module to the local repository
              nuget install $moduleName `
                -DirectDownload `
                -OutputDirectory ./__modules `
                -Source ${{ env.nugetSourceUrl }} `
                -Verbosity detailed

              ## Install the module from the local repository
              Install-Module -Name $moduleName -Repository 'localRepository'

Check out the GitHub Packages docs for more info on publishing packages to GitHub.