@@ -521,9 +521,7 @@ Fix steps:
521521
522522 # handle Restore
523523 if ($Restore -or -not (Test-Path " $ ( $Options.Top ) /obj/project.assets.json" )) {
524- log " Run dotnet restore"
525-
526- $srcProjectDirs = @ ($Options.Top , " $PSScriptRoot /src/TypeCatalogGen" , " $PSScriptRoot /src/ResGen" )
524+ $srcProjectDirs = @ ($Options.Top , " $PSScriptRoot /src/TypeCatalogGen" , " $PSScriptRoot /src/ResGen" , " $PSScriptRoot /src/Modules/PSGalleryModules.csproj" )
527525 $testProjectDirs = Get-ChildItem " $PSScriptRoot /test/*.csproj" - Recurse | ForEach-Object { [System.IO.Path ]::GetDirectoryName($_ ) }
528526
529527 $RestoreArguments = @ (" --verbosity" )
@@ -533,7 +531,11 @@ Fix steps:
533531 $RestoreArguments += " quiet"
534532 }
535533
536- ($srcProjectDirs + $testProjectDirs ) | ForEach-Object { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
534+ ($srcProjectDirs + $testProjectDirs ) | ForEach-Object {
535+ log " Run dotnet restore $_ $RestoreArguments "
536+
537+ Start-NativeExecution { dotnet restore $_ $RestoreArguments }
538+ }
537539 }
538540
539541 # handle ResGen
@@ -646,17 +648,11 @@ function Restore-PSModuleToBuild
646648 $CI
647649 )
648650
649- $ProgressPreference = " SilentlyContinue"
650651 log " Restore PowerShell modules to $publishPath "
651652
652653 $modulesDir = Join-Path - Path $publishPath - ChildPath " Modules"
653654
654- # Restore modules from powershellgallery feed
655- Restore-PSModule - Destination $modulesDir - Name @ (
656- # PowerShellGet depends on PackageManagement module, so PackageManagement module will be installed with the PowerShellGet module.
657- ' PowerShellGet'
658- ' Microsoft.PowerShell.Archive'
659- ) - SourceLocation " https://www.powershellgallery.com/api/v2/"
655+ Copy-PSGalleryModules - Destination $modulesDir
660656
661657 if ($CI.IsPresent )
662658 {
@@ -675,6 +671,7 @@ function Restore-PSPester
675671
676672 Restore-GitModule - Destination $Destination - Uri ' https://github.com/PowerShell/psl-pester' - Name Pester - CommitSha ' 1f546b6aaa0893e215e940a14f57c96f56f7eff1'
677673}
674+
678675function Compress-TestContent {
679676 [CmdletBinding ()]
680677 param (
@@ -2355,7 +2352,6 @@ function Start-CrossGen {
23552352 " Microsoft.PowerShell.Security.dll" ,
23562353 " Microsoft.PowerShell.CoreCLR.Eventing.dll" ,
23572354 " Microsoft.PowerShell.ConsoleHost.dll" ,
2358- " Microsoft.PowerShell.PSReadLine.dll" ,
23592355 " System.Management.Automation.dll"
23602356 )
23612357
@@ -2464,102 +2460,56 @@ function Restore-GitModule
24642460}
24652461
24662462# Install PowerShell modules such as PackageManagement, PowerShellGet
2467- function Restore-PSModule
2463+ function Copy-PSGalleryModules
24682464{
24692465 [CmdletBinding ()]
24702466 param (
24712467 [Parameter (Mandatory = $true )]
24722468 [ValidateNotNullOrEmpty ()]
2473- [string []]$Name ,
2474-
2475- [Parameter (Mandatory = $true )]
2476- [ValidateNotNullOrEmpty ()]
2477- [string ]$Destination ,
2478-
2479- [string ]$SourceLocation = " https://powershell.myget.org/F/powershellmodule/api/v2/" ,
2480-
2481- [string ]$RequiredVersion
2469+ [string ]$Destination
24822470 )
24832471
2484- $needRegister = $true
2485- $RepositoryName = " mygetpsmodule"
2486-
2487- # Check if the PackageManagement works in the base-oS or PowerShellCore
2488- $null = Get-PackageProvider - Name NuGet - ForceBootstrap - Verbose:$VerbosePreference
2489- $null = Get-PackageProvider - Name PowerShellGet - Verbose:$VerbosePreference
2490-
2491- # Get the existing registered PowerShellGet repositories
2492- $psrepos = PowerShellGet\Get-PSRepository
2493-
2494- foreach ($repo in $psrepos )
2495- {
2496- if (($repo.SourceLocation -eq $SourceLocation ) -or ($repo.SourceLocation.TrimEnd (" /" ) -eq $SourceLocation.TrimEnd (" /" )))
2497- {
2498- # found a registered repository that matches the source location
2499- $needRegister = $false
2500- $RepositoryName = $repo.Name
2501- break
2502- }
2472+ if (! $Destination.EndsWith (" Modules" )) {
2473+ throw " Installing to an unexpected location"
25032474 }
25042475
2505- if ($needRegister )
2506- {
2507- $regVar = PowerShellGet\Get-PSRepository - Name $RepositoryName - ErrorAction SilentlyContinue
2508- if ($regVar )
2509- {
2510- PowerShellGet\UnRegister-PSRepository - Name $RepositoryName
2511- }
2512-
2513- log " Registering PSRepository with name: $RepositoryName and sourcelocation: $SourceLocation "
2514- PowerShellGet\Register-PSRepository - Name $RepositoryName - SourceLocation $SourceLocation - ErrorVariable ev - verbose
2515- if ($ev )
2516- {
2517- throw (" Failed to register repository '{0}'" -f $RepositoryName )
2518- }
2519-
2520- $regVar = PowerShellGet\Get-PSRepository - Name $RepositoryName
2521- if (-not $regVar )
2522- {
2523- throw (" '{0}' is not registered" -f $RepositoryName )
2524- }
2476+ $cache = dotnet nuget locals global- packages - l
2477+ if ($cache -match " info : global-packages: (.*)" ) {
2478+ $nugetCache = $matches [1 ]
2479+ }
2480+ else {
2481+ throw " Can't find nuget global cache"
25252482 }
25262483
2527- log ( " Name='{0}', Destination='{1}', Repository='{2}' " -f ( $Name -join ' , ' ) , $Destination , $RepositoryName )
2484+ $psGalleryProj = [ xml ]( Get-Content - Raw $PSScriptRoot \src\Modules\PSGalleryModules.csproj )
25282485
2529- # do not output progress
2530- $ProgressPreference = " SilentlyContinue"
2531- $Name | ForEach-Object {
2486+ foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference ) {
2487+ $name = $m.Include
2488+ $version = $m.Version
2489+ log " Name='$Name ', Version='$version ', Destination='$Destination '"
25322490
2533- $command = @ {
2534- Name = $_
2535- Path = $Destination
2536- Repository = $RepositoryName
2537- }
2538-
2539- if ($RequiredVersion )
2540- {
2541- $command.Add (" RequiredVersion" , $RequiredVersion )
2491+ # Remove the build revision from the src (nuget drops it).
2492+ $srcVer = if ($version -match " (\d+.\d+.\d+).\d+" ) {
2493+ $matches [1 ]
2494+ } else {
2495+ $version
25422496 }
2543-
2544- # pull down the module
2545- log " running save-module $_ "
2546- PowerShellGet\Save-Module @command - Force
2547-
2548- # Remove PSGetModuleInfo.xml file
2549- Find-Module - Name $_ - Repository $RepositoryName - IncludeDependencies | ForEach-Object {
2550- Remove-Item - Path $Destination \$ ($_.Name )\* \PSGetModuleInfo.xml - Force
2497+ #
2498+ # Remove semantic version in the destination directory
2499+ $destVer = if ($version -match " (\d+.\d+.\d+)-.+" ) {
2500+ $matches [1 ]
2501+ } else {
2502+ $version
25512503 }
2552- }
25532504
2554- # Clean up
2555- if ($needRegister )
2556- {
2557- $regVar = PowerShellGet\Get-PSRepository - Name $RepositoryName - ErrorAction SilentlyContinue
2558- if ($regVar )
2559- {
2560- log " Unregistering PSRepository with name: $RepositoryName "
2561- PowerShellGet\UnRegister-PSRepository - Name $RepositoryName
2562- }
2505+ # Nuget seems to always use lowercase in the cache
2506+ $src = " $nugetCache /$ ( $name.ToLower ()) /$srcVer "
2507+ $dest = " $Destination /$name /$destVer "
2508+
2509+ Remove-Item - Force - ErrorAction Ignore - Recurse " $Destination /$name "
2510+ New-Item - Path $dest - ItemType Directory - Force - ErrorAction Stop > $null
2511+ $dontCopy = ' *.nupkg' , ' *.nupkg.sha512' , ' *.nuspec' , ' System.Runtime.InteropServices.RuntimeInformation.dll'
2512+ Copy-Item - Exclude $dontCopy - Recurse $src /* $dest
25632513 }
25642514}
25652515
0 commit comments