如何让 PowerShell ISE 对具有自定义扩展名的文件进行语法突出显示?
我想开始为我的一些 Powershell 脚本使用自定义扩展,但是当我将它们拖到 PowerShell ISE 中时,它们被视为纯文本,并且我没有得到任何语法突出显示。我可以做些什么来让 ISE 将我的自定义文件扩展名识别为 PowerShell 脚本吗?
I'd like to start using a custom extension for some of my Powershell scripts, but when I drag them into the PowerShell ISE, they are treated as plaintext, and I don't get any syntax highlighting. Is there anything I can do to get the ISE to recognize my custom file extension as a PowerShell script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无法完成,因为从当前版本开始,ISE 会根据文件扩展名确定是否打开语法突出显示:此行为无法更改,因为已识别的扩展名是(不幸的是)已在代码中修复。
当然,它们是:
对于那些想知道的人,ISE 在
Microsoft.PowerShell.Host.ISE.ISEFile
IsPowerShellSourceCodeFile 内部属性中确定这一点。 code> 类型,由Microsoft.PowerShell.GPowerShell
程序集导出。不,反射不允许欺骗它,因为尝试将受支持的扩展之一注入Extension
属性会导致 ISE 崩溃。Can't be done because, as of the current version, the ISE determines whether to turn syntax highlighting on or not based on the file name extension: this behavior can't be changed as the recognized extensions are (unfortunately) fixed in the code.
They are, of course:
For those who are wondering, the ISE determines this within the
IsPowerShellSourceCodeFile
internal property of theMicrosoft.PowerShell.Host.ISE.ISEFile
type, exported by theMicrosoft.PowerShell.GPowerShell
assembly. And no, reflection does not allow to cheat it, as trying to inject one of the supported extensions into theExtension
property causes the ISE to crash.我想说这是可能的。 Powershell 模块此处为 Powershell ISE 带来了 SQL 突出显示功能。
I'm going to say this is possible. The Powershell module here brings SQL highlighting to the Powershell ISE.
对我来说,PS 脚本文件扩展名无意中是
.ps
,当我将其重命名为.ps1
扩展名时,所有语法突出显示都恢复了。希望这对其他人有帮助。For me, the PS script file extension was inadvertently
.ps
, when I renamed it to have.ps1
extension, all the syntax highlighting revived. Hope this helps others.