22$script :PowerShellGet = ' PowerShellGet'
33$script :IsInbox = $PSHOME.EndsWith (' \WindowsPowerShell\v1.0' , [System.StringComparison ]::OrdinalIgnoreCase)
44$script :IsWindows = (-not (Get-Variable - Name IsWindows - ErrorAction Ignore)) -or $IsWindows
5- $script :IsLinux = (Get-Variable - Name IsLinux - ErrorAction Ignore) -and $IsLinux
6- $script :IsOSX = (Get-Variable - Name IsOSX - ErrorAction Ignore) -and $IsOSX
5+ $script :IsLinux = (Get-Variable - Name IsLinux - ErrorAction Ignore) -and $IsLinux
6+ $script :IsMacOS = (Get-Variable - Name IsMacOS - ErrorAction Ignore) -and $IsMacOS
77$script :IsCoreCLR = (Get-Variable - Name IsCoreCLR - ErrorAction Ignore) -and $IsCoreCLR
88
99if ($script :IsInbox ) {
@@ -58,54 +58,6 @@ Write-Host "PowerShellEdition value: $script:PowerShellEdition"
5858# endregion script variables
5959
6060function Install-Dependencies {
61- if ($script :PowerShellEdition -eq ' Desktop' ) {
62- $NuGetExeName = ' NuGet.exe'
63- $NugetExeFilePath = Microsoft.PowerShell.Management\Join-Path - Path $script :PSGetProgramDataPath - ChildPath $NuGetExeName
64-
65- if (-not (Test-Path - Path $NugetExeFilePath - PathType Leaf)) {
66- if (-not (Microsoft.PowerShell.Management\Test-Path - Path $script :PSGetProgramDataPath ))
67- {
68- $null = Microsoft.PowerShell.Management\New-Item - Path $script :PSGetProgramDataPath - ItemType Directory - Force
69- }
70-
71- # Download the NuGet.exe from https://nuget.org/NuGet.exe
72- Microsoft.PowerShell.Utility\Invoke-WebRequest - Uri https:// nuget.org/ NuGet.exe - OutFile $NugetExeFilePath
73- }
74-
75- Get-ChildItem $NugetExeFilePath - File
76-
77- if (-not (Get-Module - ListAvailable Pester))
78- {
79- & $NugetExeFilePath install pester - source https:// www.powershellgallery.com / api/ v2 - outputDirectory $script :ProgramFilesModulesPath - ExcludeVersion
80- }
81-
82- $AllUsersModulesPath = $script :ProgramFilesModulesPath
83- # Install latest PackageManagement module from PSGallery
84- $TempModulePath = Microsoft.PowerShell.Management\Join-Path - Path $script :TempPath - ChildPath " $ ( Get-Random ) "
85- $null = Microsoft.PowerShell.Management\New-Item - Path $TempModulePath - Force - ItemType Directory
86- $OneGetModuleName = ' PackageManagement'
87- try
88- {
89- & $NugetExeFilePath install $OneGetModuleName - source https:// dtlgalleryint.cloudapp.net/ api/ v2 - outputDirectory $TempModulePath - verbosity detailed
90- $OneGetWithVersion = Microsoft.PowerShell.Management\Get-ChildItem - Path $TempModulePath - Directory
91- $OneGetVersion = ($OneGetWithVersion.Name.Split (' .' , 2 ))[1 ]
92-
93- $OneGetModulePath = Microsoft.PowerShell.Management\Join-Path - Path $AllUsersModulesPath - ChildPath $OneGetModuleName
94- if ($PSVersionTable.PSVersion -ge ' 5.0.0' )
95- {
96- $OneGetModulePath = Microsoft.PowerShell.Management\Join-Path - Path $OneGetModulePath - ChildPath $OneGetVersion
97- }
98-
99- $null = Microsoft.PowerShell.Management\New-Item - Path $OneGetModulePath - Force - ItemType Directory
100- Microsoft.PowerShell.Management\Copy-Item - Path " $ ( $OneGetWithVersion.FullName ) \*" - Destination " $OneGetModulePath \" - Recurse - Force
101- Get-Module - ListAvailable - Name $OneGetModuleName | Microsoft.PowerShell.Core\Where-Object {$_.Version -eq $OneGetVersion }
102- }
103- finally
104- {
105- Remove-Item - Path $TempModulePath - Recurse - Force
106- }
107- }
108-
10961 # Update build title for daily builds
11062 if ($script :IsWindows -and (Test-DailyBuild )) {
11163 if ($env: APPVEYOR_PULL_REQUEST_TITLE )
@@ -178,11 +130,32 @@ function Invoke-PowerShellGetTest {
178130 $PowerShellGetTestsPath = " $ClonedProjectPath \Tests\"
179131 $PowerShellHome = Get-PSHome
180132 if ($script :IsWindows ){
181- $PowerShellExePath = Join-Path - Path $PowerShellHome - ChildPath ' PowerShell.exe'
133+ if ($script :PowerShellEdition -eq ' Core' ) {
134+ $PowerShellExePath = Join-Path - Path $PowerShellHome - ChildPath ' pwsh.exe'
135+ }
136+ else {
137+ $PowerShellExePath = Join-Path - Path $PowerShellHome - ChildPath ' PowerShell.exe'
138+ }
182139 } else {
183- $PowerShellExePath = ' powershell'
140+ $PowerShellExePath = ' pwsh'
141+ }
142+
143+ # Bootstrap NuGet.exe
144+ $NuGetExeName = ' NuGet.exe'
145+ $NugetExeFilePath = Microsoft.PowerShell.Management\Join-Path - Path $script :PSGetProgramDataPath - ChildPath $NuGetExeName
146+
147+ if (-not (Test-Path - Path $NugetExeFilePath - PathType Leaf)) {
148+ if (-not (Microsoft.PowerShell.Management\Test-Path - Path $script :PSGetProgramDataPath ))
149+ {
150+ $null = Microsoft.PowerShell.Management\New-Item - Path $script :PSGetProgramDataPath - ItemType Directory - Force
151+ }
152+
153+ # Download the NuGet.exe from https://nuget.org/NuGet.exe
154+ Microsoft.PowerShell.Utility\Invoke-WebRequest - Uri https:// nuget.org/ NuGet.exe - OutFile $NugetExeFilePath
184155 }
185156
157+ Get-ChildItem - Path $NugetExeFilePath - File
158+
186159 # Test Environment
187160 # - PowerShellGet from Current branch
188161 # - PowerShellGet packaged with PowerShellCore build:
@@ -213,6 +186,49 @@ function Invoke-PowerShellGetTest {
213186 $AllUsersModulesPath = Microsoft.PowerShell.Management\Join-Path - Path $PowerShellHome - ChildPath ' Modules'
214187 }
215188
189+ # Install latest PackageManagement from Gallery
190+ $OneGetModuleName = ' PackageManagement'
191+ $OneGetModuleInfo = Get-Module - ListAvailable - Name $OneGetModuleName | Select-Object - First 1
192+ if ($OneGetModuleInfo )
193+ {
194+ $NuGetProvider = Get-PackageProvider | Where-Object { $_.Name -eq ' NuGet' }
195+ if (-not $NuGetProvider ) {
196+ Install-PackageProvider - Name NuGet - Force
197+ }
198+
199+ $LatestOneGetInPSGallery = Find-Module - Name $OneGetModuleName
200+ if ($LatestOneGetInPSGallery.Version -gt $OneGetModuleInfo.Version ) {
201+ Install-Module - InputObject $LatestOneGetInPSGallery - Force
202+ }
203+ }
204+ else
205+ {
206+ # Install latest PackageManagement module from PSGallery
207+ $TempModulePath = Microsoft.PowerShell.Management\Join-Path - Path $script :TempPath - ChildPath " $ ( Get-Random ) "
208+ $null = Microsoft.PowerShell.Management\New-Item - Path $TempModulePath - Force - ItemType Directory
209+ $OneGetModuleName = ' PackageManagement'
210+ try
211+ {
212+ & $NugetExeFilePath install $OneGetModuleName - source https:// www.powershellgallery.com / api/ v2 - outputDirectory $TempModulePath - verbosity detailed
213+ $OneGetWithVersion = Microsoft.PowerShell.Management\Get-ChildItem - Path $TempModulePath - Directory
214+ $OneGetVersion = ($OneGetWithVersion.Name.Split (' .' , 2 ))[1 ]
215+
216+ $OneGetModulePath = Microsoft.PowerShell.Management\Join-Path - Path $AllUsersModulesPath - ChildPath $OneGetModuleName
217+ if ($PSVersionTable.PSVersion -ge ' 5.0.0' )
218+ {
219+ $OneGetModulePath = Microsoft.PowerShell.Management\Join-Path - Path $OneGetModulePath - ChildPath $OneGetVersion
220+ }
221+
222+ $null = Microsoft.PowerShell.Management\New-Item - Path $OneGetModulePath - Force - ItemType Directory
223+ Microsoft.PowerShell.Management\Copy-Item - Path " $ ( $OneGetWithVersion.FullName ) \*" - Destination " $OneGetModulePath \" - Recurse - Force
224+ Get-Module - ListAvailable - Name $OneGetModuleName | Microsoft.PowerShell.Core\Where-Object {$_.Version -eq $OneGetVersion }
225+ }
226+ finally
227+ {
228+ Remove-Item - Path $TempModulePath - Recurse - Force
229+ }
230+ }
231+
216232 # Copy OneGet and PSGet modules to PSHOME
217233 $PowerShellGetSourcePath = Microsoft.PowerShell.Management\Join-Path - Path $ClonedProjectPath - ChildPath $script :PowerShellGet
218234 $PowerShellGetModuleInfo = Test-ModuleManifest " $PowerShellGetSourcePath \PowerShellGet.psd1" - ErrorAction Ignore
@@ -237,6 +253,24 @@ function Invoke-PowerShellGetTest {
237253 Get-PSRepository;
238254 Get-Module;
239255
256+ $NuGetProvider = Get-PackageProvider | Where-Object { $_.Name -eq 'NuGet' }
257+ if(-not $NuGetProvider) {
258+ Install-PackageProvider -Name NuGet -Force
259+ }
260+
261+ # 4.0.8 version of Pester module is not compatible on MacOS, so using the Pester version installed with PWSH.
262+ if(-not (Get-Variable -Name IsMacOS -ErrorAction Ignore) -or -not $IsMacOS) {
263+ Install-Module -Name Pester -MaximumVersion 4.0.8 -Force
264+ }
265+ Get-Module -Name Pester -ListAvailable;
266+
267+ # Remove PSGetModuleInfo.xml files from the installed module bases to ensure that Update-Module tests executed properly.
268+ Get-InstalledModule -Name Pester,PackageManagement -ErrorAction SilentlyContinue | Foreach-Object {
269+ $PSGetModuleInfoXmlPath = Join-Path -Path $_.InstalledLocation -ChildPath 'PSGetModuleInfo.xml'
270+ Remove-Item -Path $PSGetModuleInfoXmlPath -Force -Verbose
271+ }
272+ Get-InstalledModule
273+
240274 # WMF 4 appveyor OS Image has duplicate entries in $env:PSModulePath
241275 if($PSVersionTable.PSVersion -le '5.0.0') {
242276 Write-Host "PSModulePath value before removing the duplicate entries:"
0 commit comments