diff --git a/build.psm1 b/build.psm1
index 50e0475e22d..f2045d1ea84 100644
--- a/build.psm1
+++ b/build.psm1
@@ -526,9 +526,7 @@ Fix steps:
# handle Restore
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")
+ $srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen", "$PSScriptRoot/src/Modules/PSGalleryModules.csproj")
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | ForEach-Object { [System.IO.Path]::GetDirectoryName($_) }
$RestoreArguments = @("--verbosity")
@@ -538,7 +536,10 @@ Fix steps:
$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
@@ -651,17 +652,11 @@ function Restore-PSModuleToBuild
$CI
)
- $ProgressPreference = "SilentlyContinue"
log "Restore PowerShell modules to $publishPath"
$modulesDir = Join-Path -Path $publishPath -ChildPath "Modules"
- # Restore modules from powershellgallery feed
- 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/"
+ Copy-PSGalleryModules -Destination $modulesDir
if($CI.IsPresent)
{
@@ -676,7 +671,7 @@ function Restore-PSPester
[ValidateNotNullOrEmpty()]
[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 {
@@ -2256,101 +2251,80 @@ function Clear-PSRepo
}
# Install PowerShell modules such as PackageManagement, PowerShellGet
-function Restore-PSModule
+function Copy-PSGalleryModules
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
- [ValidateNotNullOrEmpty()]
- [string[]]$Name,
+ [string]$Destination,
- [Parameter(Mandatory=$true)]
+ [Parameter()]
[ValidateNotNullOrEmpty()]
- [string]$Destination,
+ [string[]]$ModuleNames
+ )
- [string]$SourceLocation="https://powershell.myget.org/F/powershellmodule/api/v2/",
+ $ModulesOnlyForCI = @("Pester")
- [string]$RequiredVersion
- )
+ if (!$Destination.EndsWith("Modules")) {
+ throw "Installing to an unexpected location"
+ }
- $needRegister = $true
- $RepositoryName = "mygetpsmodule"
+ $cache = dotnet nuget locals global-packages -l
+ if ($cache -match "info : global-packages: (.*)") {
+ $nugetCache = $matches[1]
+ }
+ else {
+ throw "Can't find nuget global cache"
+ }
- # 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
+ $psGalleryProj = [xml](Get-Content -Raw $PSScriptRoot\src\Modules\PSGalleryModules.csproj)
- # Get the existing registered PowerShellGet repositories
- $psrepos = PowerShellGet\Get-PSRepository
+ foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference) {
+ $name = $m.Include
+ $version = $m.Version
- 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 ($null -ne $ModuleNames) {
+ # When '-ModuleNames' is specified, then we only copy those specified modules
+ if ($name -notin $ModuleNames) { continue }
+ } else {
+ # When '-ModuleNames' is NOT specified, copy all modules except the CI-only ones
+ if ($name -in $ModulesOnlyForCI) { continue }
}
- }
- if($needRegister)
- {
- $regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
- if($regVar)
- {
- PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
- }
+ log "Name='$Name', Version='$version', Destination='$Destination'"
- 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)
+ # Remove the build revision from the src (nuget drops it).
+ $srcVer = if ($version -match "(\d+.\d+.\d+).\d+") {
+ $matches[1]
+ } else {
+ $version
}
- $regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName
- if(-not $regVar)
- {
- throw ("'{0}' is not registered" -f $RepositoryName)
+ # Remove semantic version in the destination directory
+ $destVer = if ($version -match "(\d+.\d+.\d+)-.+") {
+ $matches[1]
+ } else {
+ $version
}
- }
- log ("Name='{0}', Destination='{1}', Repository='{2}'" -f ($Name -join ','), $Destination, $RepositoryName)
+ # Nuget seems to always use lowercase in the cache
+ $src = "$nugetCache/$($name.ToLower())/$srcVer"
+ $dest = "$Destination/$name/$destVer"
- # do not output progress
- $ProgressPreference = "SilentlyContinue"
- $Name | ForEach-Object {
-
- $command = @{
- Name=$_
- Path = $Destination
- Repository =$RepositoryName
- }
+ 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'
- if($RequiredVersion)
+ switch ($name)
{
- $command.Add("RequiredVersion", $RequiredVersion)
- }
-
- # pull down the module
- log "running save-module $_"
- PowerShellGet\Save-Module @command -Force
-
- # Remove PSGetModuleInfo.xml file
- Find-Module -Name $_ -Repository $RepositoryName -IncludeDependencies | ForEach-Object {
- Remove-Item -Path $Destination\$($_.Name)\*\PSGetModuleInfo.xml -Force
- }
- }
+ "Pester" {
+ $toolsDir = Join-Path -Path $src -ChildPath "tools"
+ Copy-Item -Path $toolsDir/* -Destination $dest -Recurse -Force
+ }
- # Clean up
- if($needRegister)
- {
- $regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
- if($regVar)
- {
- log "Unregistering PSRepository with name: $RepositoryName"
- PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
+ default {
+ Copy-Item -Exclude $dontCopy -Recurse $src/* $dest
+ }
}
}
}
diff --git a/docs/building/internals.md b/docs/building/internals.md
index e9b88df5b3f..5779f0d2e58 100644
--- a/docs/building/internals.md
+++ b/docs/building/internals.md
@@ -16,7 +16,7 @@ We are calling `dotnet` tool build for `$Top` directory
### Dummy dependencies
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.
Dummy dependencies allows us to build just `$Top` folder, instead of building several folders.
diff --git a/nuget.config b/nuget.config
index ca674f6c218..74cb0168d2f 100644
--- a/nuget.config
+++ b/nuget.config
@@ -5,5 +5,6 @@
+
diff --git a/src/Modules/PSGalleryModules.csproj b/src/Modules/PSGalleryModules.csproj
new file mode 100644
index 00000000000..47046317808
--- /dev/null
+++ b/src/Modules/PSGalleryModules.csproj
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/PSReadLine/App.config b/test/PSReadLine/App.config
deleted file mode 100644
index 8e15646352e..00000000000
--- a/test/PSReadLine/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/test/PSReadLine/AssemblyInfo.cs b/test/PSReadLine/AssemblyInfo.cs
deleted file mode 100644
index c5af7817c2a..00000000000
--- a/test/PSReadLine/AssemblyInfo.cs
+++ /dev/null
@@ -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")]
diff --git a/test/PSReadLine/PSReadLine.tests.csproj b/test/PSReadLine/PSReadLine.tests.csproj
deleted file mode 100644
index b8e2dd0e2e8..00000000000
--- a/test/PSReadLine/PSReadLine.tests.csproj
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
- PSReadLine basic tests
- TestPSReadLine
- Exe
- win7-x86;win7-x64;osx.10.12-x64;linux-x64
-
-
-
-
-
-
-
diff --git a/test/PSReadLine/Program.cs b/test/PSReadLine/Program.cs
deleted file mode 100644
index 532186898de..00000000000
--- a/test/PSReadLine/Program.cs
+++ /dev/null
@@ -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 {"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().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});
- }
- }
- }
-}
diff --git a/test/PSReadLine/packages.config b/test/PSReadLine/packages.config
deleted file mode 100644
index cae6c6db89a..00000000000
--- a/test/PSReadLine/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file