Restore modules from the NuGet package cache by using dotnet restore (#6111)
This commit is contained in:
parent
548850d249
commit
76526c6f1d
148
build.psm1
148
build.psm1
@ -526,9 +526,7 @@ Fix steps:
|
|||||||
|
|
||||||
# handle Restore
|
# handle Restore
|
||||||
if ($Restore -or -not (Test-Path "$($Options.Top)/obj/project.assets.json")) {
|
if ($Restore -or -not (Test-Path "$($Options.Top)/obj/project.assets.json")) {
|
||||||
log "Run dotnet restore"
|
$srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen", "$PSScriptRoot/src/Modules/PSGalleryModules.csproj")
|
||||||
|
|
||||||
$srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen")
|
|
||||||
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | ForEach-Object { [System.IO.Path]::GetDirectoryName($_) }
|
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | ForEach-Object { [System.IO.Path]::GetDirectoryName($_) }
|
||||||
|
|
||||||
$RestoreArguments = @("--verbosity")
|
$RestoreArguments = @("--verbosity")
|
||||||
@ -538,7 +536,10 @@ Fix steps:
|
|||||||
$RestoreArguments += "quiet"
|
$RestoreArguments += "quiet"
|
||||||
}
|
}
|
||||||
|
|
||||||
($srcProjectDirs + $testProjectDirs) | ForEach-Object { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
|
($srcProjectDirs + $testProjectDirs) | ForEach-Object {
|
||||||
|
log "Run dotnet restore $_ $RestoreArguments"
|
||||||
|
Start-NativeExecution { dotnet restore $_ $RestoreArguments }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# handle ResGen
|
# handle ResGen
|
||||||
@ -651,17 +652,11 @@ function Restore-PSModuleToBuild
|
|||||||
$CI
|
$CI
|
||||||
)
|
)
|
||||||
|
|
||||||
$ProgressPreference = "SilentlyContinue"
|
|
||||||
log "Restore PowerShell modules to $publishPath"
|
log "Restore PowerShell modules to $publishPath"
|
||||||
|
|
||||||
$modulesDir = Join-Path -Path $publishPath -ChildPath "Modules"
|
$modulesDir = Join-Path -Path $publishPath -ChildPath "Modules"
|
||||||
|
|
||||||
# Restore modules from powershellgallery feed
|
Copy-PSGalleryModules -Destination $modulesDir
|
||||||
Restore-PSModule -Destination $modulesDir -Name @(
|
|
||||||
# PowerShellGet depends on PackageManagement module, so PackageManagement module will be installed with the PowerShellGet module.
|
|
||||||
'PowerShellGet'
|
|
||||||
'Microsoft.PowerShell.Archive'
|
|
||||||
) -SourceLocation "https://www.powershellgallery.com/api/v2/"
|
|
||||||
|
|
||||||
if($CI.IsPresent)
|
if($CI.IsPresent)
|
||||||
{
|
{
|
||||||
@ -676,7 +671,7 @@ function Restore-PSPester
|
|||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string] $Destination = ([IO.Path]::Combine((Split-Path (Get-PSOptions -DefaultToNew).Output), "Modules"))
|
[string] $Destination = ([IO.Path]::Combine((Split-Path (Get-PSOptions -DefaultToNew).Output), "Modules"))
|
||||||
)
|
)
|
||||||
Save-Module -Name Pester -Path $Destination -Repository PSGallery
|
Copy-PSGalleryModules -Destination $Destination -ModuleNames Pester
|
||||||
}
|
}
|
||||||
|
|
||||||
function Compress-TestContent {
|
function Compress-TestContent {
|
||||||
@ -2309,101 +2304,80 @@ function Clear-PSRepo
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Install PowerShell modules such as PackageManagement, PowerShellGet
|
# Install PowerShell modules such as PackageManagement, PowerShellGet
|
||||||
function Restore-PSModule
|
function Copy-PSGalleryModules
|
||||||
{
|
{
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[ValidateNotNullOrEmpty()]
|
|
||||||
[string[]]$Name,
|
|
||||||
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[ValidateNotNullOrEmpty()]
|
|
||||||
[string]$Destination,
|
[string]$Destination,
|
||||||
|
|
||||||
[string]$SourceLocation="https://powershell.myget.org/F/powershellmodule/api/v2/",
|
[Parameter()]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[string[]]$ModuleNames
|
||||||
|
)
|
||||||
|
|
||||||
[string]$RequiredVersion
|
$ModulesOnlyForCI = @("Pester")
|
||||||
)
|
|
||||||
|
|
||||||
$needRegister = $true
|
if (!$Destination.EndsWith("Modules")) {
|
||||||
$RepositoryName = "mygetpsmodule"
|
throw "Installing to an unexpected location"
|
||||||
|
|
||||||
# Check if the PackageManagement works in the base-oS or PowerShellCore
|
|
||||||
$null = Get-PackageProvider -Name NuGet -ForceBootstrap -Verbose:$VerbosePreference
|
|
||||||
$null = Get-PackageProvider -Name PowerShellGet -Verbose:$VerbosePreference
|
|
||||||
|
|
||||||
# Get the existing registered PowerShellGet repositories
|
|
||||||
$psrepos = PowerShellGet\Get-PSRepository
|
|
||||||
|
|
||||||
foreach ($repo in $psrepos)
|
|
||||||
{
|
|
||||||
if(($repo.SourceLocation -eq $SourceLocation) -or ($repo.SourceLocation.TrimEnd("/") -eq $SourceLocation.TrimEnd("/")))
|
|
||||||
{
|
|
||||||
# found a registered repository that matches the source location
|
|
||||||
$needRegister = $false
|
|
||||||
$RepositoryName = $repo.Name
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($needRegister)
|
$cache = dotnet nuget locals global-packages -l
|
||||||
{
|
if ($cache -match "info : global-packages: (.*)") {
|
||||||
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
|
$nugetCache = $matches[1]
|
||||||
if($regVar)
|
}
|
||||||
{
|
else {
|
||||||
PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
|
throw "Can't find nuget global cache"
|
||||||
}
|
|
||||||
|
|
||||||
log "Registering PSRepository with name: $RepositoryName and sourcelocation: $SourceLocation"
|
|
||||||
PowerShellGet\Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -ErrorVariable ev -verbose
|
|
||||||
if($ev)
|
|
||||||
{
|
|
||||||
throw ("Failed to register repository '{0}'" -f $RepositoryName)
|
|
||||||
}
|
|
||||||
|
|
||||||
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName
|
|
||||||
if(-not $regVar)
|
|
||||||
{
|
|
||||||
throw ("'{0}' is not registered" -f $RepositoryName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log ("Name='{0}', Destination='{1}', Repository='{2}'" -f ($Name -join ','), $Destination, $RepositoryName)
|
$psGalleryProj = [xml](Get-Content -Raw $PSScriptRoot\src\Modules\PSGalleryModules.csproj)
|
||||||
|
|
||||||
# do not output progress
|
foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference) {
|
||||||
$ProgressPreference = "SilentlyContinue"
|
$name = $m.Include
|
||||||
$Name | ForEach-Object {
|
$version = $m.Version
|
||||||
|
|
||||||
$command = @{
|
if ($null -ne $ModuleNames) {
|
||||||
Name=$_
|
# When '-ModuleNames' is specified, then we only copy those specified modules
|
||||||
Path = $Destination
|
if ($name -notin $ModuleNames) { continue }
|
||||||
Repository =$RepositoryName
|
} else {
|
||||||
}
|
# When '-ModuleNames' is NOT specified, copy all modules except the CI-only ones
|
||||||
|
if ($name -in $ModulesOnlyForCI) { continue }
|
||||||
if($RequiredVersion)
|
|
||||||
{
|
|
||||||
$command.Add("RequiredVersion", $RequiredVersion)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# pull down the module
|
log "Name='$Name', Version='$version', Destination='$Destination'"
|
||||||
log "running save-module $_"
|
|
||||||
PowerShellGet\Save-Module @command -Force
|
|
||||||
|
|
||||||
# Remove PSGetModuleInfo.xml file
|
# Remove the build revision from the src (nuget drops it).
|
||||||
Find-Module -Name $_ -Repository $RepositoryName -IncludeDependencies | ForEach-Object {
|
$srcVer = if ($version -match "(\d+.\d+.\d+).\d+") {
|
||||||
Remove-Item -Path $Destination\$($_.Name)\*\PSGetModuleInfo.xml -Force
|
$matches[1]
|
||||||
|
} else {
|
||||||
|
$version
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# Clean up
|
# Remove semantic version in the destination directory
|
||||||
if($needRegister)
|
$destVer = if ($version -match "(\d+.\d+.\d+)-.+") {
|
||||||
{
|
$matches[1]
|
||||||
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
|
} else {
|
||||||
if($regVar)
|
$version
|
||||||
|
}
|
||||||
|
|
||||||
|
# Nuget seems to always use lowercase in the cache
|
||||||
|
$src = "$nugetCache/$($name.ToLower())/$srcVer"
|
||||||
|
$dest = "$Destination/$name/$destVer"
|
||||||
|
|
||||||
|
Remove-Item -Force -ErrorAction Ignore -Recurse "$Destination/$name"
|
||||||
|
New-Item -Path $dest -ItemType Directory -Force -ErrorAction Stop > $null
|
||||||
|
$dontCopy = '*.nupkg', '*.nupkg.sha512', '*.nuspec', 'System.Runtime.InteropServices.RuntimeInformation.dll'
|
||||||
|
|
||||||
|
switch ($name)
|
||||||
{
|
{
|
||||||
log "Unregistering PSRepository with name: $RepositoryName"
|
"Pester" {
|
||||||
PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
|
$toolsDir = Join-Path -Path $src -ChildPath "tools"
|
||||||
|
Copy-Item -Path $toolsDir/* -Destination $dest -Recurse -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
default {
|
||||||
|
Copy-Item -Exclude $dontCopy -Recurse $src/* $dest
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ We are calling `dotnet` tool build for `$Top` directory
|
|||||||
### Dummy dependencies
|
### Dummy dependencies
|
||||||
|
|
||||||
We use dummy dependencies between projects to leverage `dotnet` build functionality.
|
We use dummy dependencies between projects to leverage `dotnet` build functionality.
|
||||||
For example, `src\powershell-win-core\powershell-win-core.csproj` has dependency on `Microsoft.PowerShell.PSReadLine`,
|
For example, `src\powershell-win-core\powershell-win-core.csproj` has dependency on `Microsoft.PowerShell.Commands.Diagnostics.csproj`,
|
||||||
but in reality, there is no build dependency.
|
but in reality, there is no build dependency.
|
||||||
|
|
||||||
Dummy dependencies allows us to build just `$Top` folder, instead of building several folders.
|
Dummy dependencies allows us to build just `$Top` folder, instead of building several folders.
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||||
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
|
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
|
||||||
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
|
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
|
||||||
|
<add key="PSGallery" value="https://www.powershellgallery.com/api/v2/" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
12
src/Modules/PSGalleryModules.csproj
Normal file
12
src/Modules/PSGalleryModules.csproj
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
|
||||||
|
|
||||||
|
<Import Project="..\..\PowerShell.Common.props" />
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="PackageManagement" Version="1.1.7.0" />
|
||||||
|
<PackageReference Include="PowerShellGet" Version="1.6.0" />
|
||||||
|
<PackageReference Include="Microsoft.PowerShell.Archive" Version="1.1.0.0" />
|
||||||
|
<PackageReference Include="Pester" Version="4.3.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<configuration>
|
|
||||||
<startup>
|
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
|
||||||
</startup>
|
|
||||||
</configuration>
|
|
@ -1,35 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
|
||||||
// set of attributes. Change these attribute values to modify the information
|
|
||||||
// associated with an assembly.
|
|
||||||
[assembly: AssemblyTitle("TestPSReadLine")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("TestPSReadLine")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright (c) 2013")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
|
||||||
// to COM components. If you need to access a type in this assembly from
|
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|
||||||
[assembly: Guid("2892ed9f-6820-48a0-819b-0452c3b5401b")]
|
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
|
||||||
//
|
|
||||||
// Major Version
|
|
||||||
// Minor Version
|
|
||||||
// Build Number
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
|
||||||
// by using the '*' as shown below:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -1,16 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<Import Project="..\Test.Common.props"/>
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<Description>PSReadLine basic tests</Description>
|
|
||||||
<AssemblyName>TestPSReadLine</AssemblyName>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<RuntimeIdentifiers>win7-x86;win7-x64;osx.10.12-x64;linux-x64</RuntimeIdentifiers>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\src\Microsoft.PowerShell.PSReadLine\Microsoft.PowerShell.PSReadLine.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,79 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Management.Automation;
|
|
||||||
using System.Management.Automation.Runspaces;
|
|
||||||
using Microsoft.PowerShell;
|
|
||||||
|
|
||||||
namespace TestPSReadLine
|
|
||||||
{
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static void CauseCrash(ConsoleKeyInfo? key = null, object arg = null)
|
|
||||||
{
|
|
||||||
throw new Exception("intentional crash for test purposes");
|
|
||||||
}
|
|
||||||
|
|
||||||
[STAThread]
|
|
||||||
static void Main()
|
|
||||||
{
|
|
||||||
//Box(new List<string> {"abc", " def", "this is something coo"});
|
|
||||||
|
|
||||||
var iss = InitialSessionState.CreateDefault2();
|
|
||||||
var rs = RunspaceFactory.CreateRunspace(iss);
|
|
||||||
rs.Open();
|
|
||||||
Runspace.DefaultRunspace = rs;
|
|
||||||
|
|
||||||
PSConsoleReadLine.SetOptions(new SetPSReadlineOption
|
|
||||||
{
|
|
||||||
EditMode = EditMode.Emacs,
|
|
||||||
HistoryNoDuplicates = true,
|
|
||||||
});
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+LeftArrow"}, PSConsoleReadLine.ShellBackwardWord, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+RightArrow"}, PSConsoleReadLine.ShellNextWord, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"F4"}, PSConsoleReadLine.HistorySearchBackward, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"F5"}, PSConsoleReadLine.HistorySearchForward, "", "");
|
|
||||||
//PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+E"}, PSConsoleReadLine.EnableDemoMode, "", "");
|
|
||||||
//PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+D"}, PSConsoleReadLine.DisableDemoMode, "", "");
|
|
||||||
// PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+C"}, PSConsoleReadLine.CaptureScreen, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+P"}, PSConsoleReadLine.InvokePrompt, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"Ctrl+D,Ctrl+X"}, CauseCrash, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"F6"}, PSConsoleReadLine.PreviousLine, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"F7"}, PSConsoleReadLine.NextLine, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"F2"}, PSConsoleReadLine.ValidateAndAcceptLine, "", "");
|
|
||||||
PSConsoleReadLine.SetKeyHandler(new[] {"Enter"}, PSConsoleReadLine.AcceptLine, "", "");
|
|
||||||
|
|
||||||
EngineIntrinsics executionContext;
|
|
||||||
using (var ps = PowerShell.Create(RunspaceMode.CurrentRunspace))
|
|
||||||
{
|
|
||||||
executionContext =
|
|
||||||
ps.AddScript("$ExecutionContext").Invoke<EngineIntrinsics>().FirstOrDefault();
|
|
||||||
|
|
||||||
// This is a workaround to ensure the command analysis cache has been created before
|
|
||||||
// we enter into ReadLine. It's a little slow and infrequently needed, so just
|
|
||||||
// uncomment host stops responding, run it once, then comment it out again.
|
|
||||||
//ps.Commands.Clear();
|
|
||||||
//ps.AddCommand("Get-Command").Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
Console.Write("TestHostPS> ");
|
|
||||||
|
|
||||||
var line = PSConsoleReadLine.ReadLine(null, executionContext);
|
|
||||||
Console.WriteLine(line);
|
|
||||||
line = line.Trim();
|
|
||||||
if (line.Equals("exit"))
|
|
||||||
Environment.Exit(0);
|
|
||||||
if (line.Equals("cmd"))
|
|
||||||
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Windows});
|
|
||||||
if (line.Equals("emacs"))
|
|
||||||
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Emacs});
|
|
||||||
if (line.Equals("vi"))
|
|
||||||
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {EditMode = EditMode.Vi});
|
|
||||||
if (line.Equals("nodupes"))
|
|
||||||
PSConsoleReadLine.SetOptions(new SetPSReadlineOption {HistoryNoDuplicates = true});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
<package id="Microsoft.PowerShell.3.ReferenceAssemblies" version="1.0.0" targetFramework="net45" />
|
|
||||||
</packages>
|
|
Loading…
Reference in New Issue
Block a user