Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ internal static int Start(
}
#endif

// put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version
Copy link
Collaborator

@iSazonov iSazonov Aug 6, 2017

Choose a reason for hiding this comment

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

  1. Is this right for other applications?
  2. I would prefer more deterministic [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName. (Related Improve experience for side-by-side versions of PowerShell #4199 . What about Start-PowerShell cmdlet?)

string path = Environment.GetEnvironmentVariable("PATH");
string pshome = Utils.DefaultPowerShellAppBase;
if (!path.Contains(pshome))
{
Environment.SetEnvironmentVariable("PATH", pshome + Path.PathSeparator + path);
}

try
{
string profileDir;
Expand Down
6 changes: 6 additions & 0 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ foo
bash -c "unset HOME;$powershell -c '1+1'" | Should BeExactly 2
}
}

Context "PATH environment variable" {
It "`$PSHOME should be in front so that powershell.exe starts current running PowerShell" {
powershell -v | Should Match $psversiontable.GitCommitId
}
}
}

Describe "Console host api tests" -Tag CI {
Expand Down