forked from PowerShell/PSResourceGet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSModule.psm1
39 lines (31 loc) · 1.24 KB
/
PSModule.psm1
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
#
# Script module for module 'PowerShellGet'
#
Set-StrictMode -Version Latest
# Summary: PowerShellGet is supported on Windows PowerShell 5.1 or later and PowerShell 6.0+
$isCore = ($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop')
if ($isCore)
{
$script:Framework = 'netstandard2.0'
$script:FrameworkToRemove = 'net472'
} else {
$script:Framework = 'net472'
$script:FrameworkToRemove = 'netstandard2.0'
}
# Set up some helper variables to make it easier to work with the module
$script:PSModule = $ExecutionContext.SessionState.Module
$script:PSModuleRoot = $script:PSModule.ModuleBase
$script:PSGet = 'PowerShellGet.dll'
# CONSTRUCT A PATH TO THE CORRECT ASSEMBLY
$pathToAssembly = [io.path]::combine($PSScriptRoot, $framework, $PSGet)
# Remove framework binaries that are not needed
$FrameworkToRemovePath = Join-Path -Path $script:PSModuleRoot -ChildPath $script:FrameworkToRemove
Remove-Item $FrameworkToRemovePath -Force -Recurse
# NOW LOAD THE APPROPRIATE ASSEMBLY
$ImportedPSGetModule = Import-Module -Name $pathToAssembly -PassThru
if($ImportedPSGetModule)
{
$script:PSModule.OnRemove = {
Remove-Module -ModuleInfo $ImportedPSGetModule
}
}