11[CmdletBinding ()]
22param (
3- [ValidateSet (" CurrentUser" , " AllUsers" )]
4- $Scope = " CurrentUser"
3+ #
4+ [ValidateSet (" CurrentUser" , " AllUsers" , " LocalTools" )]
5+ $Scope = " CurrentUser"
56)
67
7- Push-Location $PSScriptRoot
8+ Push-Location $PSScriptRoot - StackName bootstrap - stack
89
9- # # This really does work, but using PSDepends is a lot smoother when there's more modules, or nuget packages
10+ # # This would probably work, if the default gallery was trusted ...
1011# Install-Module Pester -RequiredVersion 4.4.0 -Scope CurrentUser -Repository PSGallery -SkipPublisherCheck
1112# Install-Module Configuration -RequiredVersion 1.3.1 -Scope CurrentUser -Repository PSGallery -SkipPublisherCheck
13+ if (! (Get-Module PSDepends - ListAvailable)) {
14+ $Policy = (Get-PSRepository PSGallery).InstallationPolicy
15+ try {
16+ Set-PSRepository PSGallery - InstallationPolicy Trusted
1217
13- # Here's one example of why PowerShellGet is so awkward: their default gallery is not be trusted by default!
14- $Policy = (Get-PSRepository PSGallery).InstallationPolicy
15- Set-PSRepository PSGallery - InstallationPolicy Trusted
16- try {
17- Install-Module PSDepend - RequiredVersion 0.3 .0 - Scope:$Scope - Repository PSGallery - ErrorAction Stop
18- } finally {
19- # Make sure we didn't change anything permanently
20- Set-PSRepository PSGallery - InstallationPolicy:$Policy
18+ if ($Scope -eq " LocalTools" ) {
19+ $Target = Join-Path $PSScriptRoot " Tools"
20+ New-Item - Path $Target - ItemType Directory - Force
21+
22+ $Env: PSModulePath += ' ;' + $Target
23+ $PSDefaultParameterValues [" Invoke-PSDepend:Target" ] = $Target
24+ Save-Module PSDepend - Repository PSGallery - ErrorAction Stop - Path $Target
25+ } else {
26+ $PSDefaultParameterValues [" Invoke-PSDepend:Target" ] = $Scope
27+ Install-Module PSDepend - Repository PSGallery - ErrorAction Stop - Scope:$Scope
28+ }
29+ } finally {
30+ # Make sure we didn't change anything permanently
31+ Set-PSRepository PSGallery - InstallationPolicy:$Policy
32+ Pop-Location - StackName bootstrap- stack
33+ }
2134}
22- Import-Module PSDepend - RequiredVersion 0.3 .0
35+
36+ try {
37+ Write-Verbose " Updating dependencies"
38+ Import-Module PSDepend - ErrorAction Stop
39+ Invoke-PSDepend - Import - Force - ErrorAction Stop
40+ } catch {
41+ Write-Warning " Unable to restore dependencies. Please review errors:"
42+ throw
43+ }
0 commit comments