为什么 VS Code PowerShell 终端会映射一个新驱动器?

Why does VS Code PowerShell terminal map a new drive?

我在使用命令 Get-PSDrive 的 Visual Studio 代码中制作了一个 PowerShell 脚本,令我惊讶的是,在使用 VS Code 时,似乎有一个与我的 [=18] 相同的新驱动器=] 出现了名为 Temp 的驱动器。

据我所知,我对这个结果感到吃惊,除了我的主 C:\ 驱动器外,我只连接了 2 个其他驱动器。我试图在其他终端上复制它,但没有成功,除了 PowerShell 7:

Windows 终端 PowerShell 5.1

PowerShell 5.1

PowerShell 5.1 (86x)

PowerShell 7 (86x)

Windows 终端 PowerShell 7


当我看到它被 PwSh 7 复制时,我决定用 $host 变量检查每个 PowerShell 的版本,我看到了更意想不到的东西:

Version          : 5.1.19041.1

Windows 终端 PowerShell 5.1

Version          : 5.1.19041.1

PowerShell 5.1

Version          : 5.1.19041.1

PowerShell 5.1 (86x)

Version          : 7.0.2

PowerShell 7 (86x)

Version          : 7.0.2

Windows 终端 PowerShell 7

这一切看起来都很正常,但是当我检查VSCode $host时,我得到了结果

Version          : 2020.6.0

是什么导致了

的输出差异
Get-PSDrive | Where-Object {$_.Provider.Name -eq "FileSystem"}

在 PwSh 7、PowerShell 5.1 和 VS Code PwSh 之间?

Temp: 驱动器不是“与我的 C:\ 驱动器相同的新驱动器”;它的 Root$Env:Temp,而不是 C:\

根据实际描述 PowerShell 7.1 的 PowerShell Team May 2020 Update,这是在 PowerShell 7.0 中添加的...

In PowerShell 7.0, we added a temp: PSDrive. This works on all platforms and automatically maps to your user temporary path.

顺便说一下,您用来制作这些屏幕截图的命令可以简化为 Get-PSDrive -PSProvider FileSystem