File tree Expand file tree Collapse file tree
PSModuleDevelopment/functions/utility Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ function Publish-Local {
2+ <#
3+ . SYNOPSIS
4+ A simple function to build a local NuGet package from a module.
5+
6+ . PARAMETER PackagePath
7+ Path where the package file will be copied.
8+
9+ . PARAMETER ModulePath
10+ Path to the PowerShell module you are creating a Nuget package from
11+
12+ . EXAMPLE
13+ Publish-Local -PackagePath 'c:\temp\package' -ModulePath .\DBOps
14+ #>
15+
16+ [CmdletBinding ()]
17+ param (
18+ [string ]$PackagePath = ' C:\temp\package' ,
19+ [Parameter (mandatory = $true )]
20+ [string ]$ModulePath
21+ )
22+
23+ Write-Host " Creating package path if needed: " - NoNewline
24+ try {
25+ New-Item - Path $PackagePath - ItemType Directory - Force | Out-Null
26+ Write-Host " done" - ForegroundColor Green
27+ } catch {
28+ Write-Host " failed - $_ .Exception.Message" - ForegroundColor Red
29+ return
30+ }
31+
32+ Write-Host " Verifying Module Path: " - NoNewline
33+ if ( Test-Path - Path $ModulePath ) {
34+ Write-Host " found" - ForegroundColor green
35+ } else {
36+ Write-Host " not found" - ForegroundColor red
37+ }
38+
39+ Write-Host " Building Nuget Package..." - ForegroundColor Green
40+
41+ try {
42+ Register-PSRepository - Name ' TempLocalRepository' - PublishLocation $PackagePath - SourceLocation $PackagePath - InstallationPolicy Trusted - ErrorAction Stop
43+ Publish-Module - Path $ModulePath - Repository ' TempLocalRepository' - ErrorAction Stop
44+ Unregister-PSRepository - Name ' TempLocalRepository'
45+ Write-Host " COMPLETE - Package should now exist in: $ ( $PackagePath ) " - ForegroundColor Green
46+ } catch {
47+ Unregister-PSRepository - Name ' TempLocalRepository'
48+ Write-Host " FAILED - $_ .Exception.Message" - ForegroundColor Red
49+ return
50+ }
51+
52+ }
You can’t perform that action at this time.
0 commit comments