Repository navigation
Find help again after the help cache is reset - #28294
Open
Christian Pfeiffer (ChrisTX) wants to merge 1 commit into
Open
Christian Pfeiffer (ChrisTX) wants to merge 1 commit into
Christian Pfeiffer (ChrisTX) wants to merge 1 commit into
Conversation
When Get-Help finds the help of a cmdlet or function in a file, it sets the HelpFile property of the command to the full path of that file, and a full path in HelpFile is loaded directly from then on. Reset(), which runs after Update-Help and when the UI culture changes, cleared the cached help but kept those paths, so the session kept getting the help from the same file: the help Update-Help installed in the CurrentUser scope wasn't found when help in $PSHOME had been loaded before, and the help stayed in the previous UI culture. CommandHelpProvider now keeps the original HelpFile of the commands it changes, and Reset() restores them. Fixes PowerShell#28274 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Christian Pfeiffer (ChrisTX)
requested review from
a team,
Aditya Patwardhan (adityapatwardhan) and
Dongbo Wang (daxian-dbw)
as code owners
October 30, 2026 23:28
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the changes to help rediscovery after cache resets.
No open issues 🎉
What changed in this PR
Fixes #28274 by making Get-Help search for help again after a cache reset, rather than reuse a previously resolved file path after Update-Help or a UI culture change.
Changes:
- Tracks original command help paths with weak references and restores them on reset.
- Adds a regression test that verifies help switches from
en-UStode-DEwhen the UI culture changes.
| File | Description |
|---|---|
test/powershell/engine/Help/HelpSystem.Tests.ps1 |
Tests help rediscovery after a UI culture change. |
src/System.Management.Automation/help/CommandHelpProvider.cs |
Saves original help paths and restores them when clearing the help cache. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Fixes #28274.
When
Get-Helpfinds the help of a cmdlet or function in a file,CommandHelpProvidersets theHelpFileproperty of the command to the full path of that file. From then on,FindHelpFile()/GetHelpFile()load that path directly instead of searching for the help.Reset()runs afterUpdate-Helpand when the UI culture changes. It clears the cached help, but leaves those full paths in place, so the session keeps loading the help from the same file:Update-Help -Scope CurrentUser, help in$PSHOMEthat was loaded before keeps winning over the newly installed CurrentUser help, which is searched first otherwise (Get-Help keeps returning help it already loaded after Update-Help -Scope CurrentUser, which makes HelpSystem.Tests.ps1 flaky when $PSHOME has help #28274).This PR makes
CommandHelpProviderkeep the originalHelpFilevalue of every command it changes, andReset()restores those values, so the help is searched for again. The original values are kept in aConditionalWeakTable, so commands of removed modules aren't kept alive until the next reset.HelpFilestill shows the full path of the help file afterGet-Help, as before.The new test in
HelpSystem.Tests.ps1covers the UI culture case, as it doesn't need help in$PSHOME: a script module with help inen-USandde-DE,Get-Helpinen-US, then inde-DE. Without the fix, the secondGet-Helpreturns theen-UShelp.PR Context
Get-Helpin a session returns outdated help afterUpdate-Helpor a change of the UI culture, until a new session is started. This also makesHelpSystem.Tests.ps1fail when$PSHOMEcontains help: "Validate that get-help works for CurrentUserScope" installs the test help in the CurrentUser scope, but gets the help from$PSHOMEthat an earlier test loaded.I built and tested the change on 7.6.9 (
HelpSystem.Tests.ps1passes, including with help in$PSHOME, and the new test fails without the fix). It applies cleanly to master, but I don't have the .NET 11 SDK master needs here, so the build on master is left to CI.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header🤖 Generated with Claude Code