-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDemo.ps1
39 lines (30 loc) · 1.63 KB
/
Demo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$nugetFeedPath = Join-Path $PSScriptRoot nuget-feed
$moduleFolder = Join-Path $PSScriptRoot MyModule
Try
{
Write-Host 'Preparing self to temporary host Nuget feed' -ForegroundColor Yellow
Write-Host 'PowerShellGet need to initialize Nuget provider'
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
Write-Host 'Registering script folder as Nuget repo' -ForegroundColor Yellow
New-Item -Path $nugetFeedPath -ItemType Directory | Out-Null
Register-PSRepository -Name Demo_Nuget_Feed -SourceLocation $nugetFeedPath -PublishLocation $nugetFeedPath -InstallationPolicy Trusted | Out-Null
Write-Host 'Use Get-PSRepository to see available repos'
Write-Host 'Publishing package' -ForegroundColor Yellow
Publish-Module -Path $moduleFolder -Repository Demo_Nuget_Feed -NuGetApiKey 'use real NuGetApiKey for real nuget server here'
Write-Host 'Installing MyModule' -ForegroundColor Yellow
Install-Module -Name MyModule -Repository Demo_Nuget_Feed -Scope CurrentUser
Write-Host 'Use. Get-InstalledModule to see installed modules'
Write-Host 'Importing MyModule and using its cmdlets' -ForegroundColor Yellow
Import-Module -Name MyModule
Write-Host 'Use Get-Module to see imported modules'
Test-MyPackage
Test-MyPackageAgain
}
Finally
{
Write-Host 'Clean up: removing nuget, temporary repo and installed module' -ForegroundColor Yellow
Unregister-PSRepository Demo_Nuget_Feed -ErrorAction SilentlyContinue
Uninstall-Module -Name MyModule -ErrorAction SilentlyContinue
Remove-Module -Name MyModule -ErrorAction SilentlyContinue
Remove-Item -Path $nugetFeedPath -Recurse
}