@@ -523,7 +523,9 @@ Fix steps:
523523
524524 # handle Restore
525525 if ($Restore -or -not (Test-Path " $ ( $Options.Top ) /obj/project.assets.json" )) {
526- $srcProjectDirs = @ ($Options.Top , " $PSScriptRoot /src/TypeCatalogGen" , " $PSScriptRoot /src/ResGen" , " $PSScriptRoot /src/Modules/PSGalleryModules.csproj" )
526+ log " Run dotnet restore"
527+
528+ $srcProjectDirs = @ ($Options.Top , " $PSScriptRoot /src/TypeCatalogGen" , " $PSScriptRoot /src/ResGen" )
527529 $testProjectDirs = Get-ChildItem " $PSScriptRoot /test/*.csproj" - Recurse | ForEach-Object { [System.IO.Path ]::GetDirectoryName($_ ) }
528530
529531 $RestoreArguments = @ (" --verbosity" )
@@ -533,11 +535,7 @@ Fix steps:
533535 $RestoreArguments += " quiet"
534536 }
535537
536- ($srcProjectDirs + $testProjectDirs ) | ForEach-Object {
537- log " Run dotnet restore $_ $RestoreArguments "
538-
539- Start-NativeExecution { dotnet restore $_ $RestoreArguments }
540- }
538+ ($srcProjectDirs + $testProjectDirs ) | ForEach-Object { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
541539 }
542540
543541 # handle ResGen
@@ -650,11 +648,17 @@ function Restore-PSModuleToBuild
650648 $CI
651649 )
652650
651+ $ProgressPreference = " SilentlyContinue"
653652 log " Restore PowerShell modules to $publishPath "
654653
655654 $modulesDir = Join-Path - Path $publishPath - ChildPath " Modules"
656655
657- Copy-PSGalleryModules - Destination $modulesDir
656+ # Restore modules from powershellgallery feed
657+ Restore-PSModule - Destination $modulesDir - Name @ (
658+ # PowerShellGet depends on PackageManagement module, so PackageManagement module will be installed with the PowerShellGet module.
659+ ' PowerShellGet'
660+ ' Microsoft.PowerShell.Archive'
661+ ) - SourceLocation " https://www.powershellgallery.com/api/v2/"
658662
659663 if ($CI.IsPresent )
660664 {
@@ -673,7 +677,6 @@ function Restore-PSPester
673677
674678 Restore-GitModule - Destination $Destination - Uri ' https://github.com/PowerShell/psl-pester' - Name Pester - CommitSha ' 1f546b6aaa0893e215e940a14f57c96f56f7eff1'
675679}
676-
677680function Compress-TestContent {
678681 [CmdletBinding ()]
679682 param (
@@ -2372,6 +2375,7 @@ function Start-CrossGen {
23722375 " Microsoft.PowerShell.Security.dll" ,
23732376 " Microsoft.PowerShell.CoreCLR.Eventing.dll" ,
23742377 " Microsoft.PowerShell.ConsoleHost.dll" ,
2378+ " Microsoft.PowerShell.PSReadLine.dll" ,
23752379 " System.Management.Automation.dll"
23762380 )
23772381
@@ -2480,56 +2484,102 @@ function Restore-GitModule
24802484}
24812485
24822486# Install PowerShell modules such as PackageManagement, PowerShellGet
2483- function Copy-PSGalleryModules
2487+ function Restore-PSModule
24842488{
24852489 [CmdletBinding ()]
24862490 param (
24872491 [Parameter (Mandatory = $true )]
24882492 [ValidateNotNullOrEmpty ()]
2489- [string ]$Destination
2493+ [string []]$Name ,
2494+
2495+ [Parameter (Mandatory = $true )]
2496+ [ValidateNotNullOrEmpty ()]
2497+ [string ]$Destination ,
2498+
2499+ [string ]$SourceLocation = " https://powershell.myget.org/F/powershellmodule/api/v2/" ,
2500+
2501+ [string ]$RequiredVersion
24902502 )
24912503
2492- if (! $Destination.EndsWith (" Modules" )) {
2493- throw " Installing to an unexpected location"
2494- }
2504+ $needRegister = $true
2505+ $RepositoryName = " mygetpsmodule"
24952506
2496- $cache = dotnet nuget locals global- packages - l
2497- if ($cache -match " info : global-packages: (.*)" ) {
2498- $nugetCache = $matches [1 ]
2499- }
2500- else {
2501- throw " Can't find nuget global cache"
2507+ # Check if the PackageManagement works in the base-oS or PowerShellCore
2508+ $null = Get-PackageProvider - Name NuGet - ForceBootstrap - Verbose:$VerbosePreference
2509+ $null = Get-PackageProvider - Name PowerShellGet - Verbose:$VerbosePreference
2510+
2511+ # Get the existing registered PowerShellGet repositories
2512+ $psrepos = PowerShellGet\Get-PSRepository
2513+
2514+ foreach ($repo in $psrepos )
2515+ {
2516+ if (($repo.SourceLocation -eq $SourceLocation ) -or ($repo.SourceLocation.TrimEnd (" /" ) -eq $SourceLocation.TrimEnd (" /" )))
2517+ {
2518+ # found a registered repository that matches the source location
2519+ $needRegister = $false
2520+ $RepositoryName = $repo.Name
2521+ break
2522+ }
25022523 }
25032524
2504- $psGalleryProj = [xml ](Get-Content - Raw $PSScriptRoot \src\Modules\PSGalleryModules.csproj)
2525+ if ($needRegister )
2526+ {
2527+ $regVar = PowerShellGet\Get-PSRepository - Name $RepositoryName - ErrorAction SilentlyContinue
2528+ if ($regVar )
2529+ {
2530+ PowerShellGet\UnRegister-PSRepository - Name $RepositoryName
2531+ }
25052532
2506- foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference ) {
2507- $name = $m.Include
2508- $version = $m.Version
2509- log " Name='$Name ', Version='$version ', Destination='$Destination '"
2533+ log " Registering PSRepository with name: $RepositoryName and sourcelocation: $SourceLocation "
2534+ PowerShellGet\Register-PSRepository - Name $RepositoryName - SourceLocation $SourceLocation - ErrorVariable ev - verbose
2535+ if ($ev )
2536+ {
2537+ throw (" Failed to register repository '{0}'" -f $RepositoryName )
2538+ }
25102539
2511- # Remove the build revision from the src (nuget drops it).
2512- $srcVer = if ($version -match " (\d+.\d+.\d+).\d+" ) {
2513- $matches [1 ]
2514- } else {
2515- $version
2540+ $regVar = PowerShellGet\Get-PSRepository - Name $RepositoryName
2541+ if (-not $regVar )
2542+ {
2543+ throw (" '{0}' is not registered" -f $RepositoryName )
25162544 }
2517- #
2518- # Remove semantic version in the destination directory
2519- $destVer = if ($version -match " (\d+.\d+.\d+)-.+" ) {
2520- $matches [1 ]
2521- } else {
2522- $version
2545+ }
2546+
2547+ log (" Name='{0}', Destination='{1}', Repository='{2}'" -f ($Name -join ' ,' ), $Destination , $RepositoryName )
2548+
2549+ # do not output progress
2550+ $ProgressPreference = " SilentlyContinue"
2551+ $Name | ForEach-Object {
2552+
2553+ $command = @ {
2554+ Name = $_
2555+ Path = $Destination
2556+ Repository = $RepositoryName
2557+ }
2558+
2559+ if ($RequiredVersion )
2560+ {
2561+ $command.Add (" RequiredVersion" , $RequiredVersion )
25232562 }
25242563
2525- # Nuget seems to always use lowercase in the cache
2526- $src = " $nugetCache /$ ( $name.ToLower ()) /$srcVer "
2527- $dest = " $Destination /$name /$destVer "
2564+ # pull down the module
2565+ log " running save-module $_ "
2566+ PowerShellGet\Save-Module @command - Force
2567+
2568+ # Remove PSGetModuleInfo.xml file
2569+ Find-Module - Name $_ - Repository $RepositoryName - IncludeDependencies | ForEach-Object {
2570+ Remove-Item - Path $Destination \$ ($_.Name )\* \PSGetModuleInfo.xml - Force
2571+ }
2572+ }
25282573
2529- Remove-Item - Force - ErrorAction Ignore - Recurse " $Destination /$name "
2530- New-Item - Path $dest - ItemType Directory - Force - ErrorAction Stop > $null
2531- $dontCopy = ' *.nupkg' , ' *.nupkg.sha512' , ' *.nuspec' , ' System.Runtime.InteropServices.RuntimeInformation.dll'
2532- Copy-Item - Exclude $dontCopy - Recurse $src /* $dest
2574+ # Clean up
2575+ if ($needRegister )
2576+ {
2577+ $regVar = PowerShellGet\Get-PSRepository - Name $RepositoryName - ErrorAction SilentlyContinue
2578+ if ($regVar )
2579+ {
2580+ log " Unregistering PSRepository with name: $RepositoryName "
2581+ PowerShellGet\UnRegister-PSRepository - Name $RepositoryName
2582+ }
25332583 }
25342584}
25352585
0 commit comments