-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-dependencies.ps1
77 lines (77 loc) · 3.94 KB
/
load-dependencies.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
try {
$ModuleManifest = Test-ModuleManifest $PSScriptRoot\..\*.psd1
Write-Verbose 'Unloading typedata'
Get-Module $ModuleManifest.Name | % {
$_.ExportedTypeFiles | % {
Remove-TypeData -Path $_
}
}
# for msi modules like VMware
$ModuleManifest.RequiredModules | % {
Import-Module -Name $_.Name -RequiredVersion $_.Version -ea Stop
}
@($ModuleManifest.PrivateData.RequiredPackages) -ne $null | % {
$ProviderName,$PackageName,$Version,$Source = $_.CanonicalId.Split(':/#')
$RequiredPackage = $_
switch -Regex ($ProviderName) {
'nuget' {
#nuget:Microsoft.Exchange.WebServices/2.2#nuget.org
$Destination = Join-Path $RequiredPackage.Destination "$PackageName.$Version"
if (-not (Test-Path $Destination)) {
Write-Warning "Installing package $PackageName version $Version from source $Source"
# how to skip dependencies?
Install-Package -ProviderName $ProviderName -Name $PackageName -RequiredVersion $Version -Source $Source -Destination $RequiredPackage.Destination
}
Write-Verbose 'Loading assemblies'
$RequiredPackage.RequiredAssemblies | % {
Add-Type -Path (Join-Path $Destination $_)
}
#$Package.PackageFilename -replace '\.nupkg$'
}
'powershellget|gitlab' {
#powershellget:PSScriptAnalyzer/1.5.0#PSGallery
#gitlab:Networking/1.2.0#Intermedia
$Module = Get-Module -Name $PackageName -ListAvailable | ? Version -eq $Version
if (-not $Module) {
Write-Warning "Installing module $PackageName version $Version from source $Source"
Import-PackageProvider $ProviderName
switch ($ProviderName) {
powershellget {
Install-Module -Name $PackageName -RequiredVersion $Version -Repository $Source
}
gitlab {
$Credential = Get-Credential -Message "Provider $ProviderName source $Source"
Install-Package -ProviderName $ProviderName -Credential $Credential -Name $PackageName -RequiredVersion $Version -Source $Source
}
}
}
Import-Module -Name $PackageName -RequiredVersion $Version -WarningAction SilentlyContinue -ea Stop
}
'chocolatey' {
#chocolatey:OpenSSL.Light/1.1.0.20160926#
# until Chocolatey provider did not go GA
$Package = choco list $PackageName --local-only
if (-not ($Package -eq "$PackageName $Version")) {
Write-Warning "Installing package $PackageName version $Version from source $Source"
choco install -y $PackageName --version $Version
}
$Destination = $RequiredPackage.Destination
#$Package = Get-Package -Name $PackageName -RequiredVersion $Version -ProviderName $ProviderName
#if (-not $Package) {
# Install-Package -Name $PackageName -RequiredVersion $Version -ProviderName $ProviderName
#}
}
'.*' {
if ($env:Path -notlike "*$Destination*" -and $RequiredPackage.EnvPath) {
Write-Verbose 'Updating $Path'
$MachinePath = [System.Environment]::GetEnvironmentVariable('Path','Machine')
[System.Environment]::SetEnvironmentVariable('Path',$MachinePath + ";$Destination",'Machine')
$env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine')
}
}
}
}
} catch {
Write-Error $_.Exception
throw 'Failed to load required dependency'
}