Publish PowerShell Module
Publish to GitHub Packages as a NuGet Package
Pre-Requisites:
- Install the latest
BETA
version ofPowerShellGet
from the PowerShell Gallery:
# Ensuring PowerShellGet stable is latest version
Install-Module -Name PowerShellGet -Force -AllowClobber
# Installing PowerShellGet 3 Prerelease
Install-Module -Name PowerShellGet -RequiredVersion 3.0.16-beta16 -AllowPrerelease -Force -Repository PSGallery -SkipPublisherCheck
- Install the NuGet CLI
winget install Microsoft.NuGet
- Install the gpr tool:
dotnet tool install --global gpr
- Create a Personal Access Token
with the
read:packages
andwrite:packages
scopes.
gh secret set --user GHPKG_TOKEN -b $ENV:GHPKG_TOKEN
Workflow
- Create a "local"
Nuget
Repository:
New-Item -Path $LocalRepoPath -Type Directory | Out-Null
Register-PSResourceRepository -Name "LocalRepo" -Uri $LocalRepoPath
- Publish the module to the local repository as a PSResource:
Publish-PSResource -Path "./*.psd1" -Repository "LocalRepo"
- Using
gpr
, publish to GitHub Packages for your repository:
$NupkgPath = Get-ChildItem -Path $LocalRepoPath -Include "*.nupkg" -Recurse
gpr push -k $Env:GHPKG_TOKEN $NupkgPath -r "https://github.com/<user>/<repo>"
Publish to PowerShell Gallery
Publish-PSResource -Path <path/to/module> -Repository "PSGallery" -ApiKey $Env:NUGET_API_TOKEN
or using the build.ps1
script:
# setup API key
$apiKey = $Env:NUGET_API_TOKEN | ConvertTo-SecureString -AsPlainText -Force
$cred = [pscredential]::new('apikey', $apiKey)
# run build "Publish" task
./build.ps1 -Publish -PSGalleryApiKey $cred -Bootstrap