powershell - 如何让 PowerShell ISE 对具有自定义扩展名的文件进行语法突出显示?

标签 powershell powershell-ise

我想开始为我的一些 Powershell 脚本使用自定义扩展,但是当我将它们拖到 PowerShell ISE 中时,它们被视为纯文本,并且我没有得到任何语法突出显示。我可以做些什么来让 ISE 将我的自定义文件扩展名识别为 PowerShell 脚本?

最佳答案

做不到因为,从当前版本开始,ISE 会根据文件扩展名确定是否打开语法突出显示:此行为无法更改,因为已识别的扩展名(不幸地)在代码中已修复。

他们当然是:

  • .ps1
  • .psm1
  • .psd1

  • 对于那些想知道的人,ISE 在 IsPowerShellSourceCodeFile 中确定这一点。 Microsoft.PowerShell.Host.ISE.ISEFile 的内部属性类型,由 Microsoft.PowerShell.GPowerShell 导出部件。不,反射不允许欺骗它,因为试图将支持的扩展之一注入(inject) Extension属性导致 ISE 崩溃。

    关于powershell - 如何让 PowerShell ISE 对具有自定义扩展名的文件进行语法突出显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6142750/

    相关文章:

    Powershell显示弹出窗口并不断更新弹出窗口的while循环体

    powershell - 处理 Power-Shell JSON 对象中的日期

    powershell - 在 PowerShell 中重新加载路径

    powershell 最大/第一个/聚合函数

    .net - Powershell-将COM对象类型转换为字符串

    regex - Powershell在具有特殊字符的数组中搜索字符串

    powershell - 使用powershell在字符串末尾获取int

    powershell - 如何在 PowerShell 中使用 Set-NetConnectionProfile 更改 NetConnectionProfile 的名称

    Powershell ISE 中出现 Python 错误

    powershell - 如何在 PowerShell ISE 中加载配置文件?