Visual Studio Code无法从Powershell中打开。

4
我试图使用Powershell中的code命令在文件夹内打开Visual Studio Code。然而每次尝试时,我都会得到以下错误信息:

Blockquote code : The term 'code' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + code . + ~~~~ + CategoryInfo : ObjectNotFound: (code:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException


2
正如错误消息所述:命令“code”未被识别。该命令需要在您的“Path”环境变量中的目录中。 - Bill_Stewart
是的,即使我使用正确的路径,它也无法在VS Code中打开,即使我只想打开VS Code(程序而不是项目),我仍然会收到此错误。 - user12475368
@Bill_Stewart 我也曾认为是这个问题,但我进行了一些研究,并找到了这个已关闭的问题:https://github.com/Microsoft/vscode/issues/22881。我认为你(@Horbachus)可以在这里找到解决方案。 - juan_marti
2个回答

5

我发现了一个关闭的GitHub问题(https://github.com/Microsoft/vscode/issues/22881),里面有完全相同的问题和解决方案。对于寻求解决方案的人来说,这个解决方案是:

Go to File > Preferences > Settings

Change the property "terminal.integrated.shell.windows" as follows:
      "terminal.integrated.shell.windows": "C:\Windows\System32\cmd.exe"

Restart visual studio.

这告诉VSCode使用旧的Windows批处理命令行,而不是PowerShell。我认为你应该在那里放置pwsh.exe的路径。 - Mark Stouffer

3
安装 Visual Studio Code 时,安装程序中有一个复选框,标注为:

添加到 PATH(需要重新启动 shell)

installer image

请确保勾选此选项,并在安装完成后重新启动任何活动的 shell 实例。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接