Skip to content

Conversation

@jshigetomi
Copy link

@jshigetomi jshigetomi commented Jan 7, 2026

PR Summary

This pull request upgrades the PSReadLine project to target .NET 8 and PowerShell 7.4+, removing legacy and polyfill code for older frameworks. It updates all project files, build scripts, and dependencies to use the latest versions, and enforces compatibility at both the module and script level. The most important changes are summarized below.

Framework and Dependency Upgrades:

  • All projects (PSReadLine, MockPSConsole, and tests) now target .NET 8.0 exclusively, removing support for older frameworks such as netstandard2.0, net472, and net6.0. Corresponding dependencies are updated to the latest compatible versions, including Microsoft.PowerShell.SDK 7.4.0. ([[1]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-15b49bb2c4d47eeb9db538533ac5b972f85f34ba280b7acb42c1b5c27db438e9L8-R21), [[2]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-3fcef917fe90ddf5a3b2ef1d86c3505ec20ab64f86c0febed8d682b19f8a84a3L7-R14), [[3]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-08cd1f3a887d8dcf95b9437203d198df174e72fa3bed3645db09901adb95ac2fL8-R8), [[4]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-08cd1f3a887d8dcf95b9437203d198df174e72fa3bed3645db09901adb95ac2fL17-R18))
  • The build process and global.json are updated to require .NET SDK 8.0.416. ([[1]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-8df3cd354bc584349d04ad5675b33c042d8b99b741b8b95af394c55e0f5001bfR1-R7), [[2]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-cf52a72665faf1250da83a9745360bf052fadf8f4a395bf0557d6f1b6ffcec18L22-L63))

PowerShell Version Requirement:

  • The module manifest (PSReadLine.psd1) and the main module script (PSReadLine.psm1) now require PowerShell 7.4 or later. The script throws a clear error if loaded in an older version, with instructions for users. ([[1]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-249c945874c86bf263442fb1b4ffbc108e8642a3ce9b0d05a6e1b103a7933bbeL4-R10), [[2]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-7a6a99977c8583b1131f983549f09dac821eb025205e76fa1d4ce533438bcb4aR1-R14))

Removal of Legacy and Polyfill Code:

  • The Polyfill project and related code (including CommandPrediction.cs and Polyfill.csproj) are deleted, simplifying the codebase and eliminating support for legacy PowerShell versions. Build scripts are updated to remove all polyfill-related tasks. ([[1]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-ed6d8ebde2b95773782d7bbedbc734f0a7f97b1d70355fee2e6b9f130329481fL1-L232), [[2]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-9bbfd47219535f7987f69c047ce2324aba293c39340a1edb0be346d75cde5f0aL1-L22), [[3]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-cf52a72665faf1250da83a9745360bf052fadf8f4a395bf0557d6f1b6ffcec18L22-L63), [[4]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-cf52a72665faf1250da83a9745360bf052fadf8f4a395bf0557d6f1b6ffcec18L100-R92), [[5]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-cf52a72665faf1250da83a9745360bf052fadf8f4a395bf0557d6f1b6ffcec18L118-R110))

Version Bump:

  • The PSReadLine module version is updated to 3.0.0 across all relevant files, reflecting the breaking changes and new requirements. ([[1]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-15b49bb2c4d47eeb9db538533ac5b972f85f34ba280b7acb42c1b5c27db438e9L8-R21), [[2]](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-249c945874c86bf263442fb1b4ffbc108e8642a3ce9b0d05a6e1b103a7933bbeL4-R10))

Development Environment Updates:

  • The VS Code launch configuration is updated to reference the new build output path for .NET 8.0. ([.vscode/launch.jsonL17-R17](https://github.com/PowerShell/PSReadLine/pull/5055/files#diff-bd5430ee7c51dc892a67b3f2829d1f5b6d223f0fd48b82322cfd45baf9f5e945L17-R17))

These changes modernize PSReadLine, streamline its development and deployment, and ensure compatibility with the latest PowerShell and .NET releases.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure you've added one or more new tests
  • Make sure you've tested these changes in terminals that PowerShell is commonly used in (i.e. conhost.exe, Windows Terminal, Visual Studio Code Integrated Terminal, etc.)
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed at PowerShell-Docs
      • Doc Issue filed:
Microsoft Reviewers: Open in CodeFlow

To upgrade PowerShell: https://aka.ms/install-powershell
"@
throw $errorMessage
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PowerShellVersion = '7.4' in the psd1 file will prevent the module from being loaded, so if PSReadLine.psm1 will never get executed for a PS session older than 7.4. So, this change is not needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case where can we write the user friendly error message?
I think the error message will show up like this if we rely on psd1 file

Import-Module: The specified module 'PSReadLine' was not loaded because no valid module file was found in any module directory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think the error message will call out that the PSReadLine requires PowerShell 7.4 and thus cannot be loaded.

In the long run, I don't think we can always tell the user which PSReadLine version is for which PS version, they need to find out in document, something similar to the PowerShell Support Lifecycle.

@jshigetomi
Copy link
Author

jshigetomi commented Jan 13, 2026

Fix test failures after migrating to .NET 8.0 / PowerShell 7.4+

After migrating PSReadLine to .NET 8.0 targeting PowerShell 7.4+, the test
infrastructure needed updates to handle modern ANSI escape sequences that
PSReadLine now emits.

Root Cause:
The migration enabled PSReadLine to use more sophisticated ANSI rendering.
Code in Cmdlets.cs (lines 160-193) now dynamically selects between:

  • Modern: \x1b[97;2;3m (White + Dim + Italic) for newer terminals
  • Legacy: \x1b[38;5;238m (256-color gray) for older environments

Both rendering paths required MockConsole support to prevent test failures.

Changes:

  1. test/MockConsole.cs

    • Added 256-color ANSI parsing (38;5;n, 48;5;n sequences)
    • Added font effects parsing (1=bold, 2=dim, 3=italic)
    • These sequences were previously unhandled, causing KeyNotFoundException
    • Implemented in both TestConsole.Write() and BasicScrollingConsole.Write()
  2. test/UnitTestReadLine.cs

    • Changed Colors[0] from ConsoleColor.DarkRed to ConsoleColor.White
    • MockConsole's ANSI reset handler (\x1b[0m) sets ForegroundColor = Colors[0]
    • Tests expect White for dimmed text, but were getting DarkRed after resets
    • This mismatch caused 16 test failures on CI
  3. test/InlinePredictionTest.cs

    • Added documentation comment explaining Emitted256Colors tracking
    • Helps future test authors validate 256-color emission

Why These Changes Were Necessary:

  • 256-color parsing: Prevents KeyNotFoundException when PSReadLine emits
    \x1b[38;5;238m on older Windows or specific terminal configurations

  • Font effects parsing: Prevents errors when PSReadLine emits \x1b[97;2;3m
    for dimmed italic text on modern terminals (Windows 11 22H2+, Windows Terminal)

  • Colors[0] fix: Ensures ANSI reset sequences restore the expected default
    color (White) rather than the arbitrary test default (DarkRed)

@jshigetomi jshigetomi requested a review from daxian-dbw January 13, 2026 17:35
<PackageReference Include="Microsoft.CSharp" version="4.7.0" />
<PackageReference Include="Microsoft.PowerShell.Pager" version="1.0.0" />
<ProjectReference Include="..\Polyfill\Polyfill.csproj" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.13" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed to reference the sdk package.

<ExcludeAssets>contentFiles</ExcludeAssets>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed after targeting net8.0?

<PackageReference Include="Microsoft.PowerShell.Pager" Version="1.0.0" />
</ItemGroup>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space

Microsoft.PowerShell.Core\Set-StrictMode -Off
[Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext, $lastRunStatus)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please revert this change? I think you deleted the ending newline of this file.

internal static readonly ConsoleColor[] Colors = new []
{
/*None*/ ConsoleColor.DarkRed,
/*None*/ ConsoleColor.White,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does any of this need to be changed?

Comment on lines +14 to +15
dotnet nuget remove source PowerShell_PublicPackages
dotnet nuget add source https://api.nuget.org/v3/index.json --name nuget.org
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the missing packages to the PowerShell_PublicPackages instead of changing it to nuget.org.
Otherwise, a community contributor may not be able to build PSReadLine locally because we are using PowerShell_PublicPackages feed in nuget.config at the project root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants