Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example script for publishing a PowerShell module to the NuGet GitHub Package Registry
<# --
Register the GitHub Package Registry
-- #>
$username = '<github-username>'
$token = '<github-personal-token>'
$sourceName = 'GitHub'
$source = "https://nuget.pkg.github.com/$username/index.json"
# add the github package registry as a nuget source
nuget sources Add -Name $sourceName -Source $source -UserName $username -Password $token
# register the github package registry as a powershell repository
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, (ConvertTo-SecureString -AsPlainText $token -Force)
Register-PSRepository -Name $sourceName -SourceLocation $source -PublishLocation $source -Credential $creds
<# --
Publish PowerShell module
-- #>
$module = '<module-name>'
$version = '<module-version>'
$apiKey = 'n/a' # keep this as n/a!
Publish-Module -Name $module -Repository $sourceName -RequiredVersion $version -Credential $creds -Force -NuGetApiKey $apiKey
@SeidChr
Copy link

SeidChr commented Oct 29, 2020

As far as i know, github packages will put packages within their respective repositories
How does it know the repository, when the source location only contains the username?
Is the "$module / <module-name>" used for this?

@Badgerati
Copy link
Author

Badgerati commented Nov 1, 2020

From what I remember, the source index.json was a list of all repos, and NuGet was clever enough to work out where to push to based on that and the module's name - so long as your repo/module had the same name.

@SeidChr
Copy link

SeidChr commented Nov 1, 2020

ok, so module name must match.

unfortunately I couldn't make your sample work
first I got packaging errors and after updating the powershellget module I get an authentication error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment