[feature] Add -CustomPipeName to pwsh and Enter-PSHostProcess#8889
Conversation
src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Outdated
Show resolved
Hide resolved
PaulHigin
left a comment
There was a problem hiding this comment.
I will finish the review later, but have a couple of comments now.
Thanks!
src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/LocalConnection.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/commands/EnterPSHostProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1
Outdated
Show resolved
Hide resolved
PaulHigin
left a comment
There was a problem hiding this comment.
Let's remove the connection of pipe listener creation to local runspace, and think about whether we want to replace the existing default IPC channel or create a second one when starting powershell.exe in DebugPipeName mode, although I think we should use a different name for the switch, like IPCPipe or CustomIPCPipe, or something.
src/System.Management.Automation/engine/hostifaces/LocalConnection.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs
Outdated
Show resolved
Hide resolved
pwsh and Enter-PSHostProcesspwsh and Enter-PSHostProcess
|
@PaulHigin I've refactored this quite a bit based on your offline feedback. The same experience is there for a user at the CLI. For users that are going through the API, the can use: S.M.A.Remoting.RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer("mypipe");There is 1 thing left to do here:
|
d47a632 to
d7df174
Compare
pwsh and Enter-PSHostProcesspwsh and Enter-PSHostProcess
src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/commands/EnterPSHostProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/commands/EnterPSHostProcessCommand.cs
Outdated
Show resolved
Hide resolved
|
Addressed all feedback 👍 |
PaulHigin
left a comment
There was a problem hiding this comment.
LGTM. But please create new Issue about disposing pipe server objects on process exit (please see comment).
src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs
Show resolved
Hide resolved
|
Ok I included a few CodeFactor and Codacy fixes as well. This should be good to go pending CI ✅ |
src/System.Management.Automation/engine/remoting/commands/EnterPSHostProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/commands/EnterPSHostProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs
Show resolved
Hide resolved
src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/Enter-PSHostProcess.Tests.ps1
Outdated
Show resolved
Hide resolved
|
I've addressed @PaulHigin's final point which is that It's mostly used for debugging though... and our usecase is really for debugging... so I've called this out in the His recommendation and what I went with was |
pwsh and Enter-PSHostProcesspwsh and Enter-PSHostProcess
| case ProcessIdParameterSet: | ||
| Process = GetProcessById(Id); | ||
| VerifyProcess(Process); | ||
| namedPipeRunspace = CreateNamedPipeRunspace(Process.Id, AppDomainName); |
There was a problem hiding this comment.
Interesting, do we really need the VerifyProcess() check (that is File.Exist())? Perhaps the runtime error is informative enough.
There was a problem hiding this comment.
I'm not quite sure what you're saying. This VerifyProcess is to keep the behavior consistent with the current behavior for Process parameter sets.
|
@TylerLeonhardt Please create new Issue in PowerShell-Docs repo and add reference to the PR description. |
|
Alright CI is green and codacy and Code Factor are mostly happy. This should be good to go. |
iSazonov
left a comment
There was a problem hiding this comment.
LGTM with minor comments.
src/System.Management.Automation/engine/remoting/commands/EnterPSHostProcessCommand.cs
Outdated
Show resolved
Hide resolved
|
@TylerLeonhardt Please create new Issue in PowerShell-Docs repo before we merge. |
|
Done, @iSazonov! |
|
@TylerLeonhardt Thanks for your contribution! |
PR Summary
This allows a user to start PowerShell up with the name of the named pipe that is used for cross process communication (I.e.
Enter-PSHostProcess).Example:
terminal 1
terminal 2
PR Context
Today, it is impossible to predictively connect to a PowerShell process without knowing its process id. If you're stopping and starting a powershell process often... you have no mechanism for figuring out the process id.
This introduces a consistent way to connect to a PowerShell process by specifying the NamedPipe yourself.
This is very nice in PowerShell hosted scenarios - for example, in Azure Functions where PowerShell is hosted. This enables the ability to consistently connect to the PowerShell instance hosted there without any additional information besides the CustomPipeName that can be reused.
This feature also means that in the PowerShell extension for VSCode, we can achieve "Attach to Process" debugging with a single stroke of the F5 key.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.pwshandEnter-PSHostProcessMicrosoftDocs/PowerShell-Docs#3755[feature]to your commit messages if the change is significant or affects feature tests