Skip to content

Commit 5a82b10

Browse files
chunqingchenmirichmo
authored andcommitted
Get-Help should find help files under pshome (PowerShell#3528)
1 parent 11ad02a commit 5a82b10

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

src/System.Management.Automation/help/HelpProvider.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,30 +222,20 @@ internal void ReportHelpFileError(Exception exception, string target, string hel
222222

223223
/// <summary>
224224
/// Each Shell ( minishell ) will have its own path specified by the
225-
/// registry HKLM\software\microsoft\msh\1\ShellIds\&lt;ShellID&gt;\path. Every help
226-
/// provider should search this path for content.
225+
/// application base folder, which should be the same as $pshome
227226
/// </summary>
228227
/// <returns>string representing base directory of the executing shell.</returns>
229228
internal string GetDefaultShellSearchPath()
230229
{
231230
string shellID = this.HelpSystem.ExecutionContext.ShellID;
232-
string returnValue = CommandDiscovery.GetShellPathFromRegistry(shellID);
231+
// Beginning in PowerShell 6.0.0.12, the $pshome is no longer registry specified, we search the application base instead.
232+
string returnValue = Utils.GetApplicationBase(shellID);
233233

234234
if (returnValue == null)
235235
{
236236
// use executing assemblies location in case registry entry not found
237237
returnValue = Path.GetDirectoryName(PsUtils.GetMainModule(System.Diagnostics.Process.GetCurrentProcess()).FileName);
238238
}
239-
else
240-
{
241-
// Get the directory path of the executing shell
242-
returnValue = Path.GetDirectoryName(returnValue);
243-
if (!Directory.Exists(returnValue))
244-
{
245-
// use executing assemblies location in case registry entry not found
246-
returnValue = Path.GetDirectoryName(PsUtils.GetMainModule(System.Diagnostics.Process.GetCurrentProcess()).FileName);
247-
}
248-
}
249239

250240
return returnValue;
251241
}

test/powershell/engine/Help/HelpSystem.Tests.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,28 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @('
201201
$help | Should BeExactly "Hello"
202202
}
203203
}
204+
205+
Describe "Get-Help should find help info within help files" -Tags @('CI', 'RequireAdminOnWindows') {
206+
It "Get-Help should find help files under pshome" {
207+
$helpFile = "about_testCase.help.txt"
208+
$culture = (Get-Culture).Name
209+
$helpFolderPath = Join-Path $PSHOME $culture
210+
$helpFilePath = Join-Path $helpFolderPath $helpFile
211+
212+
if (!(Test-Path $helpFolderPath))
213+
{
214+
$null = New-Item -ItemType Directory -Path $helpFolderPath -ErrorAction SilentlyContinue
215+
}
216+
217+
try
218+
{
219+
$null = New-Item -ItemType File -Path $helpFilePath -Value "about_test" -ErrorAction SilentlyContinue
220+
$helpContent = Get-Help about_testCase
221+
$helpContent | Should Match "about_test"
222+
}
223+
finally
224+
{
225+
Remove-Item $helpFilePath -Force -ErrorAction SilentlyContinue
226+
}
227+
}
228+
}

0 commit comments

Comments
 (0)