qbo4.PublishModule.ps1
<#
Publish a Powershell module to a Nuget feed such as the Powershell Gallery. To use directly: cd c:\source\devops\quandis\qbo4.Infrastructure\src\qbo4.Infrastructure.Powershell\bin\debug\net48 Import-Module (Resolve-Path('c:\source\devops\quandis\qbo4.Infrastructure\src\qbo4.Infrastructure.Powershell\bin\debug\net48\qbo4.Infrastructure.psd1')) -verbose Import-Module .\qbo4.PublishModule.ps1 import-qboModule qbo4.Infrastructure . -verbose publish-qboModule qbo4.Infrastructure #> function Import-qboModule { <# .SYNOPSIS Publishes a Powershell module to a Nuget feed. Intended for use after a build, either on a developer's machine or via DevOps release pipeline. .INPUTS Name: name of the powershell module (must have a matching .psd1 files) Path: path to the Output Directory from a build. ApiKey: api key to the Nuget repo for publishing #> [CmdletBinding()] Param( [Parameter(Position=0, Mandatory=$true)] [string]$Name, [Parameter(Position=1, Mandatory=$true)] [string]$Path ) $folder = "$($env:temp)\$($name)" Write-Verbose "Copying output folder to $folder" md $folder -ErrorAction SilentlyContinue del $folder\* copy $path\* $folder Write-Verbose "Importing $name.psd1" import-module -FullyQualifiedName $folder\$name.psd1 } function Publish-qboModule { <# .SYNOPSIS Publishes a Powershell module to a Nuget feed. Intended for use after a build, either on a developer's machine or via DevOps release pipeline. .INPUTS Name: name of the powershell module (must have a matching .psd1 files) Path: path to the Output Directory from a build. ApiKey: api key to the Nuget repo for publishing #> [CmdletBinding()] Param( [Parameter(Position=0)] [string]$Name, [Parameter(Position=1)] [string]$Path, [Parameter(Position=2)] [string]$ApiKey ) Import-qboModule $name $path if ($ApiKey -eq $null) { $ApiKey = read-qboConfig -key NugetApiKey -promptsecure "Nuget repo API key" } $version = (get-module qbo4.Infrastructure).Version $newVersion = [version]::new($version.Major, $version.Minor, $version.Build, $version.Revision + 1) Write-Verbose "Updating version from $version to $newVersion" Update-ModuleManifest -Path $folder\$name.psd1 -ModuleVersion $newVersion Write-Verbose "Publishing module" Publish-Module -Path $folder -NuGetApiKey $ApiKey } |