我想包括一些仅在 VSCode 内部运行时才会发生的 Powershell 自定义。
在 ISE 或包管理控制台内(在 Visual Studio 内)时,我可以使用 $host.name
的值切换行为或在“主机特定”powershell 配置文件中包含特定代码(例如 Microsoft.PowerShell_profile.ps1
)。
VSCode 中的 Powershell 看起来与在常规控制台中运行的 Powershell 相同,因此这些选项中的大多数都不可用。有没有办法解决这个问题?
最佳答案
另见 Visual Studio Code $psise equivalent
您可以检查 $psISE,如果它不存在,请尝试 $context = [Microsoft.Powershell.EditorServices.Extensions.EditorContext]$psEditor.GetEditorContext()
但请注意,这会导致 ISE。
我在很多脚本中都使用了这个片段,所以我总是可以引用“$root”。
# Makes debugging from ISE easier.
if ($PSScriptRoot -eq "")
{
if ($psISE)
{
$root = Split-Path -Parent $psISE.CurrentFile.FullPath
}
else
{
$context = $psEditor.GetEditorContext()
$root = Split-Path -Parent $context.CurrentFile.Path
}
}
else
{
$root = $PSScriptRoot
}
关于powershell - 在 VSCode 集成终端内运行时如何自定义 powershell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48511874/