共计 969 个字符,预计需要花费 3 分钟才能阅读完成。
在开发过程中,我们可能需要将 PowerShell 7 作为默认PowerShell 版本。
首先,我们需要下载PowerShell 7。
你可以在Github上下载PowerShell的安装程序,或者使用WinGet来进行安装。
通过以下命令,可使用已发布的 winget 包安装 PowerShell:
使用系统自带的powershell 搜索最新版本的powershell:
winget search Microsoft.PowerShell
一般情况会显示一个正式版和一个预览版
Name Id Version Source
---------------------------------------------------------------
PowerShell Microsoft.PowerShell 7.5.0.0 winget
PowerShell Preview Microsoft.PowerShell.Preview 7.6.0.2 winget
使用 id
参数安装 PowerShell 或 PowerShell 预览版
正式版 :
winget install --id Microsoft.PowerShell --source winget
预览版是这个:
winget install --id Microsoft.PowerShell.Preview --source winget
正常情况下,等待一分钟即可安装成功。
然后,打开终端设置页面
右键开始菜单,或者按下“Win+X”,打开“终端管理员”,并打开终端的设置页面。
在Windows PowerShell 页面的“命令行”中,点击“浏览”,选择powershell的可执行文件“pwsh.exe”,该文件放在“C:\Program Files\PowerShell\7”文件夹下。
另外,如果你不喜欢打开PowerShell后,上面出现PowerShell的版本号,你可以在pwsh.exe的位置后面加上这样一段参数:
-noexit -command Set-Location -literalPath "($pwd)"
比如我电脑中的路径就是:
C:\Program Files\PowerShell\7\pwsh.exe -noexit -command Set-Location -literalPath "($pwd)"
最后切记点击“保存”。这是加上参数后的效果:
正文完