No PSEdit cmdlet and $dte.ExecuteCommand("File.OpenFile", "[FullPathAndFileName]") Sometimes Works and Sometimes Hangs VS
For VS Community 2017 v. 15.9.13, | PoshTools v. 4.7.1 (not Pro) | $PSVersionTable output at end
The PowerShell Interactive Window does not have the standard PowerShell cmdlet PSEdit to open a file for editing in VS.
The native VS interface command exposed by $dte -- $dte.ExecuteCommand("File.OpenFile", "[FullPathAndFileName.ps1]") (“Open” also can be used in place of “File.OpenFile”) – should work to do this in the Interactive Window.
However, that $dte command only works sometimes (not, however, opening the .ps1 file as a debuggable script--which is a separate issue that likely has other reasons--perhaps not being opened as part of a VS solution?), but much more often, it just completely hangs VS without any Ctrl+C execution break or other escape mechanism other than killing VS through Task Manager.
Further, creating a function to mimic PSEdit, e.g.:
function psEdit {
param ([string]$FileName)
$dte.ExecuteCommand("Open", "$FileName")
}
in the Interactive Window only sometimes works, but, like the direct command it represents, most often, it hangs VS as well. Further, this function definition never works when it is created in the $profile file (which would be the ideal way to include the missing psEdit functionality in PoshTools).
PSVersion 5.1.15063.1563
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.15063.1563
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Comments (1)
-
reporter - Log in to comment
Here is more information about the above problem:
If VS has been started but no PowerShell solution is open, the Interactive Window generally works and, when it is first opened, it generally runs $profile.
If $profile has run, the psEdit function will not generate an error (if $profile did not run, this error is generated: [ERROR] psEdit : The term 'psEdit' is not recognized as the name of a cmdlet, function, script file, or operable program. ….), but it will hang VS and require terminating it by Task Manager.
However, if VS has been started and a PowerShell solution is open, and the Interactive Window ran $profile when first opened, then psEdit works as it should per the above definition of the function.
The problem seems to be whether or not a PowerShell solution is open, and, if not, even though the Interactive Window works for most of its intended functionality, if fails doing so in at least this important respect.