@@ -521,9 +521,7 @@ Fix steps:
521
521
522
522
# handle Restore
523
523
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" )
527
525
$testProjectDirs = Get-ChildItem " $PSScriptRoot /test/*.csproj" - Recurse | ForEach-Object { [System.IO.Path ]::GetDirectoryName($_ ) }
528
526
529
527
$RestoreArguments = @ (" --verbosity" )
@@ -533,7 +531,11 @@ Fix steps:
533
531
$RestoreArguments += " quiet"
534
532
}
535
533
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
+ }
537
539
}
538
540
539
541
# handle ResGen
@@ -646,17 +648,11 @@ function Restore-PSModuleToBuild
646
648
$CI
647
649
)
648
650
649
- $ProgressPreference = " SilentlyContinue"
650
651
log " Restore PowerShell modules to $publishPath "
651
652
652
653
$modulesDir = Join-Path - Path $publishPath - ChildPath " Modules"
653
654
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
660
656
661
657
if ($CI.IsPresent )
662
658
{
@@ -675,6 +671,7 @@ function Restore-PSPester
675
671
676
672
Restore-GitModule - Destination $Destination - Uri ' https://github.com/PowerShell/psl-pester' - Name Pester - CommitSha ' 1f546b6aaa0893e215e940a14f57c96f56f7eff1'
677
673
}
674
+
678
675
function Compress-TestContent {
679
676
[CmdletBinding ()]
680
677
param (
@@ -2355,7 +2352,6 @@ function Start-CrossGen {
2355
2352
" Microsoft.PowerShell.Security.dll" ,
2356
2353
" Microsoft.PowerShell.CoreCLR.Eventing.dll" ,
2357
2354
" Microsoft.PowerShell.ConsoleHost.dll" ,
2358
- " Microsoft.PowerShell.PSReadLine.dll" ,
2359
2355
" System.Management.Automation.dll"
2360
2356
)
2361
2357
@@ -2464,102 +2460,56 @@ function Restore-GitModule
2464
2460
}
2465
2461
2466
2462
# Install PowerShell modules such as PackageManagement, PowerShellGet
2467
- function Restore-PSModule
2463
+ function Copy-PSGalleryModules
2468
2464
{
2469
2465
[CmdletBinding ()]
2470
2466
param (
2471
2467
[Parameter (Mandatory = $true )]
2472
2468
[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
2482
2470
)
2483
2471
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"
2503
2474
}
2504
2475
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"
2525
2482
}
2526
2483
2527
- log ( " Name='{0}', Destination='{1}', Repository='{2}' " -f ( $Name -join ' , ' ) , $Destination , $RepositoryName )
2484
+ $psGalleryProj = [ xml ]( Get-Content - Raw $PSScriptRoot \src\Modules\PSGalleryModules.csproj )
2528
2485
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 '"
2532
2490
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
2542
2496
}
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
2551
2503
}
2552
- }
2553
2504
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
2563
2513
}
2564
2514
}
2565
2515
0 commit comments