1

I have been able to successfully publish a PowerShell module of my own creation to the repo's GitHub Packages location. I have utilized several resources to get that accomplished.

The problem comes in after that. I cannot seem to be able to run Find-Module and get anything from the specified registered PSRepository.

If I delete the package so there are no collisions, I can register a PSRepository with the GitHub Package location:

Register-PSRepository -Name GitHub -SourceLocation https://nuget.pkg.github.com/beau-witter/index.json -PublishLocation https://nuget.pkg.github.com/beau-witter/index.json -InstallationPolicy Trusted

and then publish to that Repository without issue:

Publish-Module -Path path/to/module -Repository GitHub -NuGetApiKey "<GITHUB_API_KEY>"

If I run that publish again, I will receive the error:

Write-Error: Failed to publish module 'NetworkAnalyzer': 'nuget.exe failed to push Response status code does not indicate success: 409 (Conflict). '.

Indicating that the first publish was successful and now can't put the same package at the same version in that location.

However, running Find-Module -Repository GitHub -Credential $BuiltCredentialObject I just receive null back. Everything on the GitHub page for Working with the NuGet registry seems to explicitly assume this is going through a .NET project/or solution with .csproj files and running dotnet. Besides that, the actual steps for installing seems pretty hand-wavy and unclear. This NuGet Issue on GitHub seems to suggest it can be done:

Can GitHub act as a PSRepository which would make PowerShellGet commands see it as a PSRepository?

In theory, yes. See https://docs.microsoft.com/en-us/powershell/scripting/gallery/how-to/working-with-local-psrepositories?view=powershell-6

But again, that is dealing almost entirely with Publishing, not consuming.

Is it possible to actually consume the valid PowerShell modules from the GitHub Packages NuGet package repository?

B. Witter
  • 564
  • 6
  • 19

1 Answers1

0

While digging deeply within each of my provided resources, I found a diamond hiding in all the information that failed to help me before.

In this StackOverflow Answer the user adds a link at the bottom of their answer that takes you to this comment on a GitHub issue for PowerShellGet.

After updating my PSDepend to add PowerShellGet as a dependency (allowing for Prerelease), and following the pattern laid out in the PowerShellGet Issue comment

Register-PSResourceRepository -Name GitHub -URL https://nuget.pkg.github.com/beau-witter/index.json
Install-PSResource -Name NetworkAnalyzer -Repository GitHub -Credential $BuiltCredentialObject

I am able to consume the PowerShell Module from the GitHub Packages NuGet repository!

So it seems that, for the time being, consuming PowerShell Modules from a GitHub Packages NuGet repository may only be possible in Powershell 7+ using the beta of PowerShellGet v3.

Edit: More details. It appears that GitHub Packages is still not officially supported even with PowerShellGet v3 (beta). So this solution only currently works on a Windows machine. I do not know the lowest version this works on, but 3.0.19 beta19 of PowerShellGet does allow to run Install-PSResource with GitHub Packages as the repository.

Note: The secrets.GITHUB_TOKEN, even with Read-Write, appears to not be authorized to the GitHub Packages NuGet repository, so a sufficient PAT is still necessary.

B. Witter
  • 564
  • 6
  • 19