diff --git a/.vscode/launch.json b/.vscode/launch.json
index c01006234..f15ddc52f 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -14,7 +14,7 @@
"-NoProfile",
"-NoExit",
"-Command",
- "Import-Module '${workspaceFolder}/PSReadLine/bin/Debug/netstandard2.0/PSReadLine.psd1'"
+ "Import-Module '${workspaceFolder}/PSReadLine/bin/Debug/net8.0/PSReadLine.psd1'"
],
"console": "integratedTerminal",
"justMyCode": false,
diff --git a/MockPSConsole/MockPSConsole.csproj b/MockPSConsole/MockPSConsole.csproj
index cebd3941d..d0f91fa71 100644
--- a/MockPSConsole/MockPSConsole.csproj
+++ b/MockPSConsole/MockPSConsole.csproj
@@ -4,18 +4,14 @@
Exe
MockPSConsole
MockPSConsole
- net472;net6.0
+ net8.0
512
Program.manifest
true
-
-
-
-
-
-
+
+
diff --git a/PSReadLine.build.ps1 b/PSReadLine.build.ps1
index e245dfae3..4d54be206 100644
--- a/PSReadLine.build.ps1
+++ b/PSReadLine.build.ps1
@@ -19,46 +19,37 @@ param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = (property Configuration Release),
- [ValidateSet("net472", "net6.0")]
- [string]$TestFramework,
-
[switch]$CheckHelpContent
)
Import-Module "$PSScriptRoot/tools/helper.psm1"
-# Final bits to release go here
-$targetDir = "bin/$Configuration/PSReadLine"
+# Dynamically read target framework from project file
+$csprojPath = "$PSScriptRoot/PSReadLine/PSReadLine.csproj"
+[xml]$csproj = Get-Content $csprojPath
+$targetFramework = $csproj.Project.PropertyGroup.TargetFramework | Where-Object { $_ } | Select-Object -First 1
-if (-not $TestFramework) {
- $TestFramework = $IsWindows ? "net472" : "net6.0"
+if (-not $targetFramework) {
+ throw "Could not determine TargetFramework from $csprojPath"
}
+Write-Verbose "Target framework: $targetFramework"
+
+# Final bits to release go here
+$targetDir = "bin/$Configuration/PSReadLine"
+
function ConvertTo-CRLF([string] $text) {
$text.Replace("`r`n","`n").Replace("`n","`r`n")
}
-$polyFillerParams = @{
- Inputs = { Get-ChildItem Polyfill/*.cs, Polyfill/Polyfill.csproj }
- Outputs = "Polyfill/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll"
-}
-
$binaryModuleParams = @{
- Inputs = { Get-ChildItem PSReadLine/*.cs, PSReadLine/PSReadLine.csproj, PSReadLine/PSReadLineResources.resx, Polyfill/*.cs, Polyfill/Polyfill.csproj }
- Outputs = "PSReadLine/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.dll"
+ Inputs = { Get-ChildItem PSReadLine/*.cs, PSReadLine/PSReadLine.csproj, PSReadLine/PSReadLineResources.resx }
+ Outputs = "PSReadLine/bin/$Configuration/$targetFramework/Microsoft.PowerShell.PSReadLine.dll"
}
$xUnitTestParams = @{
Inputs = { Get-ChildItem test/*.cs, test/*.json, test/PSReadLine.Tests.csproj }
- Outputs = "test/bin/$Configuration/$TestFramework/PSReadLine.Tests.dll"
-}
-
-<#
-Synopsis: Build the Polyfiller assembly
-#>
-task BuildPolyfiller @polyFillerParams {
- exec { dotnet publish -c $Configuration -f 'netstandard2.0' Polyfill }
- exec { dotnet publish -c $Configuration -f 'net6.0' Polyfill }
+ Outputs = "test/bin/$Configuration/$targetFramework/PSReadLine.Tests.dll"
}
<#
@@ -72,15 +63,15 @@ task BuildMainModule @binaryModuleParams {
Synopsis: Build xUnit tests
#>
task BuildXUnitTests @xUnitTestParams {
- exec { dotnet publish -f $TestFramework -c $Configuration test }
+ exec { dotnet publish -f $targetFramework -c $Configuration test }
}
<#
Synopsis: Run the unit tests
#>
task RunTests BuildMainModule, BuildXUnitTests, {
- Write-Verbose "Run tests targeting '$TestFramework' ..."
- Start-TestRun -Configuration $Configuration -Framework $TestFramework
+ Write-Verbose "Run tests targeting $targetFramework ..."
+ Start-TestRun -Configuration $Configuration -Framework $targetFramework
}
<#
@@ -97,7 +88,7 @@ task CheckHelpContent -If $CheckHelpContent {
<#
Synopsis: Copy all of the files that belong in the module to one place in the layout for installation
#>
-task LayoutModule BuildPolyfiller, BuildMainModule, {
+task LayoutModule BuildMainModule, {
if (-not (Test-Path $targetDir -PathType Container)) {
New-Item $targetDir -ItemType Directory -Force > $null
}
@@ -115,17 +106,7 @@ task LayoutModule BuildPolyfiller, BuildMainModule, {
Set-Content -Path (Join-Path $targetDir (Split-Path $file -Leaf)) -Value (ConvertTo-CRLF $content) -Force
}
- if (-not (Test-Path "$targetDir/netstd")) {
- New-Item "$targetDir/netstd" -ItemType Directory -Force > $null
- }
- if (-not (Test-Path "$targetDir/net6plus")) {
- New-Item "$targetDir/net6plus" -ItemType Directory -Force > $null
- }
-
- Copy-Item "Polyfill/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/netstd" -Force
- Copy-Item "Polyfill/bin/$Configuration/net6.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net6plus" -Force
-
- $binPath = "PSReadLine/bin/$Configuration/netstandard2.0/publish"
+ $binPath = "PSReadLine/bin/$Configuration/$targetFramework/publish"
Copy-Item $binPath/Microsoft.PowerShell.PSReadLine.dll $targetDir
Copy-Item $binPath/Microsoft.PowerShell.Pager.dll $targetDir
diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs
index 5633a69af..596b1548e 100644
--- a/PSReadLine/Cmdlets.cs
+++ b/PSReadLine/Cmdlets.cs
@@ -178,7 +178,7 @@ static PSConsoleReadLineOptions()
// Our tests expect that the default inline-view color is set to the new color, so we configure
// the color based on system environment only if we are not in test runs.
- if (AppDomain.CurrentDomain.FriendlyName is not "PSReadLine.Tests")
+ if (AppDomain.CurrentDomain.FriendlyName is not "testhost")
{
DefaultInlinePredictionColor =
Environment.OSVersion.Version.Build >= 22621 // on Windows 11 22H2 or newer versions
diff --git a/PSReadLine/OnImportAndRemove.cs b/PSReadLine/OnImportAndRemove.cs
deleted file mode 100644
index 70208420a..000000000
--- a/PSReadLine/OnImportAndRemove.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using System;
-using System.IO;
-using System.Management.Automation;
-using System.Reflection;
-
-namespace Microsoft.PowerShell.PSReadLine
-{
- public class OnModuleImportAndRemove : IModuleAssemblyInitializer, IModuleAssemblyCleanup
- {
- public void OnImport()
- {
- AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
- }
-
- public void OnRemove(PSModuleInfo module)
- {
- AppDomain.CurrentDomain.AssemblyResolve -= ResolveAssembly;
- }
-
- ///
- /// Load the correct 'Polyfiller' assembly based on the runtime.
- ///
- private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
- {
- if (args.Name != "Microsoft.PowerShell.PSReadLine.Polyfiller, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
- {
- return null;
- }
-
- string root = Path.GetDirectoryName(typeof(OnModuleImportAndRemove).Assembly.Location);
- string subd = (Environment.Version.Major >= 6) ? "net6plus" : "netstd";
- string path = Path.Combine(root, subd, "Microsoft.PowerShell.PSReadLine.Polyfiller.dll");
-
- return Assembly.LoadFrom(path);
- }
- }
-}
diff --git a/PSReadLine/PSReadLine.csproj b/PSReadLine/PSReadLine.csproj
index f67e29e4c..edb39c91b 100644
--- a/PSReadLine/PSReadLine.csproj
+++ b/PSReadLine/PSReadLine.csproj
@@ -5,21 +5,22 @@
Microsoft.PowerShell.PSReadLine
Microsoft.PowerShell.PSReadLine
$(NoWarn);CA1416
- 2.4.5.0
- 2.4.5
- 2.4.5
+ 3.0.0.0
+ 3.0.0
+ 3.0.0
true
- netstandard2.0
+ net8.0
true
false
9.0
-
-
-
-
+
+ contentFiles
+ All
+
+
diff --git a/PSReadLine/PSReadLine.psd1 b/PSReadLine/PSReadLine.psd1
index 0690e85cc..4ce7eff73 100644
--- a/PSReadLine/PSReadLine.psd1
+++ b/PSReadLine/PSReadLine.psd1
@@ -1,13 +1,13 @@
@{
RootModule = 'PSReadLine.psm1'
NestedModules = @("Microsoft.PowerShell.PSReadLine.dll")
-ModuleVersion = '2.4.5'
+ModuleVersion = '3.0.0'
GUID = '5714753b-2afd-4492-a5fd-01d9e2cff8b5'
Author = 'Microsoft Corporation'
CompanyName = 'Microsoft Corporation'
Copyright = '(c) Microsoft Corporation. All rights reserved.'
Description = 'Great command line editing in the PowerShell console host'
-PowerShellVersion = '5.1'
+PowerShellVersion = '7.4'
FormatsToProcess = 'PSReadLine.format.ps1xml'
AliasesToExport = @()
FunctionsToExport = 'PSConsoleHostReadLine'
diff --git a/Polyfill/CommandPrediction.cs b/Polyfill/CommandPrediction.cs
deleted file mode 100644
index e7b331a8b..000000000
--- a/Polyfill/CommandPrediction.cs
+++ /dev/null
@@ -1,232 +0,0 @@
-#if LEGACY
-
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using System.Management.Automation.Language;
-
-namespace System.Management.Automation.Subsystem.Prediction
-{
- ///
- /// Kinds of prediction clients.
- ///
- public enum PredictionClientKind
- {
- ///
- /// A terminal client, representing the command-line experience.
- ///
- Terminal,
-
- ///
- /// An editor client, representing the editor experience.
- ///
- Editor,
- }
-
- ///
- /// The class represents a client that interacts with predictors.
- ///
- public sealed class PredictionClient
- {
- ///
- /// Gets the client name.
- ///
- [HiddenAttribute]
- public string Name { get; }
-
- ///
- /// Gets the client kind.
- ///
- [HiddenAttribute]
- public PredictionClientKind Kind { get; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Name of the interactive client.
- /// Kind of the interactive client.
- [HiddenAttribute]
- public PredictionClient(string name, PredictionClientKind kind)
- {
- Name = name;
- Kind = kind;
- }
- }
-
- ///
- /// The class represents the prediction result from a predictor.
- ///
- public sealed class PredictionResult
- {
- ///
- /// Gets the Id of the predictor.
- ///
- [HiddenAttribute]
- public Guid Id { get; }
-
- ///
- /// Gets the name of the predictor.
- ///
- [HiddenAttribute]
- public string Name { get; }
-
- ///
- /// Gets the mini-session id that represents a specific invocation that returns this result.
- /// When it's not specified, it's considered by a client that the predictor doesn't expect feedback.
- ///
- [HiddenAttribute]
- public uint? Session { get; }
-
- ///
- /// Gets the suggestions.
- ///
- [HiddenAttribute]
- public IReadOnlyList Suggestions { get; }
-
- internal PredictionResult(Guid id, string name, uint? session, List suggestions)
- {
- Id = id;
- Name = name;
- Session = session;
- Suggestions = suggestions;
- }
- }
-
- ///
- /// The class represents a predictive suggestion generated by a predictor.
- ///
- public sealed class PredictiveSuggestion
- {
- ///
- /// Gets the suggestion.
- ///
- [HiddenAttribute]
- public string SuggestionText { get; }
-
- ///
- /// Gets the tooltip of the suggestion.
- ///
- [HiddenAttribute]
- public string ToolTip { get; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The predictive suggestion text.
- [HiddenAttribute]
- public PredictiveSuggestion(string suggestion)
- : this(suggestion, toolTip: null)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The predictive suggestion text.
- /// The tooltip of the suggestion.
- [HiddenAttribute]
- public PredictiveSuggestion(string suggestion, string toolTip)
- {
- if (string.IsNullOrEmpty(suggestion))
- {
- throw new ArgumentNullException(nameof(suggestion));
- }
-
- SuggestionText = suggestion;
- ToolTip = toolTip;
- }
- }
-
- ///
- /// Provides a set of possible predictions for given input.
- ///
- public static class CommandPrediction
- {
- ///
- /// Collect the predictive suggestions from registered predictors using the default timeout.
- ///
- /// Represents the client that initiates the call.
- /// The object from parsing the current command line input.
- /// The objects from parsing the current command line input.
- /// A list of objects.
- [HiddenAttribute]
- public static Task> PredictInputAsync(PredictionClient client, Ast ast, Token[] astTokens)
- {
- return null;
- }
-
- ///
- /// Collect the predictive suggestions from registered predictors using the specified timeout.
- ///
- /// Represents the client that initiates the call.
- /// The object from parsing the current command line input.
- /// The objects from parsing the current command line input.
- /// The milliseconds to timeout.
- /// A list of objects.
- [HiddenAttribute]
- public static Task> PredictInputAsync(PredictionClient client, Ast ast, Token[] astTokens, int millisecondsTimeout)
- {
- return null;
- }
-
- ///
- /// Allow registered predictors to do early processing when a command line is accepted.
- ///
- /// Represents the client that initiates the call.
- /// History command lines provided as references for prediction.
- [HiddenAttribute]
- public static void OnCommandLineAccepted(PredictionClient client, IReadOnlyList history)
- {
- }
-
- ///
- /// Allow registered predictors to know the execution result (success/failure) of the last accepted command line.
- ///
- /// Represents the client that initiates the call.
- /// The last accepted command line.
- /// Whether the execution of the last command line was successful.
- [HiddenAttribute]
- public static void OnCommandLineExecuted(PredictionClient client, string commandLine, bool success)
- {
- }
-
- ///
- /// Send feedback to a predictor when one or more suggestions from it were displayed to the user.
- ///
- /// Represents the client that initiates the call.
- /// The identifier of the predictor whose prediction result was accepted.
- /// The mini-session where the displayed suggestions came from.
- ///
- /// When the value is > 0, it's the number of displayed suggestions from the list returned in , starting from the index 0.
- /// When the value is <= 0, it means a single suggestion from the list got displayed, and the index is the absolute value.
- ///
- [HiddenAttribute]
- public static void OnSuggestionDisplayed(PredictionClient client, Guid predictorId, uint session, int countOrIndex)
- {
- }
-
- ///
- /// Send feedback to predictors about their last suggestions.
- ///
- /// Represents the client that initiates the call.
- /// The identifier of the predictor whose prediction result was accepted.
- /// The mini-session where the accepted suggestion came from.
- /// The accepted suggestion text.
- [HiddenAttribute]
- public static void OnSuggestionAccepted(PredictionClient client, Guid predictorId, uint session, string suggestionText)
- {
- }
- }
-}
-
-#else
-
-using System.Management.Automation.Subsystem.Prediction;
-using System.Runtime.CompilerServices;
-
-[assembly: TypeForwardedTo(typeof(PredictionClientKind))]
-[assembly: TypeForwardedTo(typeof(PredictionClient))]
-[assembly: TypeForwardedTo(typeof(PredictiveSuggestion))]
-[assembly: TypeForwardedTo(typeof(PredictionResult))]
-[assembly: TypeForwardedTo(typeof(CommandPrediction))]
-
-#endif
diff --git a/Polyfill/Polyfill.csproj b/Polyfill/Polyfill.csproj
deleted file mode 100644
index 2cdccfbba..000000000
--- a/Polyfill/Polyfill.csproj
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
- Microsoft.PowerShell.PSReadLine.Polyfiller
- 1.0.0.0
- netstandard2.0;net6.0
- true
-
-
-
-
-
-
-
-
-
-
-
- $(DefineConstants);LEGACY
-
-
-
diff --git a/appveyor.yml b/appveyor.yml
index 0bc286805..84ed4dce3 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -19,7 +19,7 @@ build_script:
./build.ps1 -Configuration Release
test_script:
- - pwsh: ./build.ps1 -Test -Configuration Release -Framework net472
+ - pwsh: ./build.ps1 -Test -Configuration Release
artifacts:
- path: .\bin\Release\PSReadLine.zip
diff --git a/build.ps1 b/build.ps1
index 481f2a271..8871b2179 100644
--- a/build.ps1
+++ b/build.ps1
@@ -5,18 +5,20 @@
A script that provides simple entry points for bootstrapping, building and testing.
.DESCRIPTION
A script to make it easy to bootstrap, build and run tests.
+ This build targets .NET 8.0, which is the runtime for PowerShell 7.4 LTS.
+ PowerShell 7.4 LTS is supported until November 2026.
.EXAMPLE
PS > .\build.ps1 -Bootstrap
Check and install prerequisites for the build.
.EXAMPLE
PS > .\build.ps1 -Configuration Release
- Build the main module with 'Release' configuration targeting 'netstandard2.0'.
+ Build the project in Release configuration.
.EXAMPLE
PS > .\build.ps1
- Build the main module with the default configuration (Debug) targeting 'netstandard2.0'.
+ Build the main module with the default configuration (Debug) configuration.
.EXAMPLE
PS > .\build.ps1 -Test
- Run xUnit tests with the default configuration (Debug) and the default target framework (net472 on Windows or net6.0 otherwise).
+ Run xUnit tests with the default configuration.
.PARAMETER Clean
Clean the local repo, but keep untracked files.
.PARAMETER Bootstrap
@@ -25,13 +27,6 @@
Run tests.
.PARAMETER Configuration
The configuration setting for the build. The default value is 'Debug'.
-.PARAMETER Framework
- The target framework when testing:
- - net472: run tests with .NET Framework
- - net6.0: run tests with .NET 6.0
- When not specified, the target framework is determined by the current OS platform:
- - use 'net472' on Windows
- - use 'net6.0' on Unix platforms
#>
[CmdletBinding(DefaultParameterSetName = 'default')]
param(
@@ -47,10 +42,6 @@ param(
[Parameter(ParameterSetName = 'test')]
[switch] $CheckHelpContent,
- [Parameter(ParameterSetName = 'test')]
- [ValidateSet("net472", "net6.0")]
- [string] $Framework,
-
[Parameter(ParameterSetName = 'default')]
[Parameter(ParameterSetName = 'test')]
[ValidateSet("Debug", "Release")]
@@ -93,7 +84,6 @@ if (-not (Get-Module -Name InvokeBuild -ListAvailable)) {
$buildTask = if ($Test) { "RunTests" } else { "ZipRelease" }
$arguments = @{ Task = $buildTask; Configuration = $Configuration }
-if ($Framework) { $arguments.Add("TestFramework", $Framework) }
if ($CheckHelpContent) { $arguments.Add("CheckHelpContent", $true) }
Invoke-Build @arguments
diff --git a/global.json b/global.json
new file mode 100644
index 000000000..d23a6248a
--- /dev/null
+++ b/global.json
@@ -0,0 +1,5 @@
+{
+ "sdk": {
+ "version": "8.0.415"
+ }
+}
diff --git a/test/InlinePredictionTest.cs b/test/InlinePredictionTest.cs
index febf0ac1f..db6145164 100644
--- a/test/InlinePredictionTest.cs
+++ b/test/InlinePredictionTest.cs
@@ -638,7 +638,7 @@ public void Inline_HistoryAndPluginSource_Acceptance()
Assert.Equal(Guid.Empty, _mockedMethods.acceptedPredictorId);
Assert.Null(_mockedMethods.acceptedSuggestion);
Assert.NotNull(_mockedMethods.commandHistory);
- Assert.Equal(1, _mockedMethods.commandHistory.Count);
+ Assert.Single(_mockedMethods.commandHistory);
Assert.Equal("netsh show me", _mockedMethods.commandHistory[0]);
_mockedMethods.ClearPredictionFields();
diff --git a/test/PSReadLine.Tests.csproj b/test/PSReadLine.Tests.csproj
index 34598cbe9..3cf7aee80 100644
--- a/test/PSReadLine.Tests.csproj
+++ b/test/PSReadLine.Tests.csproj
@@ -5,7 +5,7 @@
library
UnitTestPSReadLine
PSReadLine.Tests
- net472;net6.0
+ net8.0
512
{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
False
@@ -14,13 +14,8 @@
9.0
-
-
-
-
-
-
-
+
+
diff --git a/tools/helper.psm1 b/tools/helper.psm1
index a79532a8f..56776ea9a 100644
--- a/tools/helper.psm1
+++ b/tools/helper.psm1
@@ -1,9 +1,13 @@
-$MinimalSDKVersion = '6.0.425'
$IsWindowsEnv = [System.Environment]::OSVersion.Platform -eq "Win32NT"
$RepoRoot = (Resolve-Path "$PSScriptRoot/..").Path
$LocalDotnetDirPath = if ($IsWindowsEnv) { "$env:LocalAppData\Microsoft\dotnet" } else { "$env:HOME/.dotnet" }
+# Read the required SDK version from global.json
+$globalJsonPath = Join-Path $RepoRoot "global.json"
+$globalJson = Get-Content -Path $globalJsonPath -Raw | ConvertFrom-Json
+$MinimalSDKVersion = $globalJson.sdk.version
+
<#
.SYNOPSIS
Get the path of the currently running powershell executable.
@@ -54,7 +58,7 @@ function Test-DotnetSDK
if (Test-Path $dotnetExePath) {
$installedVersion = & $dotnetExePath --version
- return $installedVersion -ge $MinimalSDKVersion
+ return [Version]::new($installedVersion) -ge [Version]::new($MinimalSDKVersion)
}
return $false
}
@@ -211,13 +215,15 @@ function Start-TestRun
function RunXunitTestsInNewProcess ([string] $Layout, [string] $OperatingSystem)
{
$filter = if ($Layout) {
- Write-Log "Testing $Layout on $OperatingSystem...`n"
+ Write-Log "`nTesting $Layout on $OperatingSystem..."
"FullyQualifiedName~Test.{0}_{1}" -f ($Layout -replace '-','_'), $OperatingSystem
} else {
## Today, tests for screen-reader mode only run on Windows with the 'en-US' layout.
- Write-Log "Testing screen reader mode...`n"
+ $Layout = "screen-reader"
+ Write-Log "`nTesting $Layout mode..."
"FullyQualifiedName~Test.ScreenReader"
}
+
$testResultFile = "xUnitTestResults.{0}.xml" -f $Layout
$testResultFile = Join-Path $testResultFolder $testResultFile
@@ -279,7 +285,7 @@ function Start-TestRun
}
else
{
- Write-Log "Testing not supported for the keyboard layout '$layout'."
+ Write-Log "`nTesting not supported for the keyboard layout '$layout'."
}
}
}
@@ -289,6 +295,7 @@ function Start-TestRun
$null = [KeyboardLayoutHelper]::SetKeyboardLayout($savedLayout)
}
}
+
RunXunitTestsInNewProcess
}
else