简体   繁体   English

通过 VS 开发人员命令提示符打开的 VS 代码无法识别“cl”

[英]VS Code opened via VS Developer Command Prompt not recognizing 'cl'

As the title says, VS Code is not recognizing cl compiler although opened via Visual Studio 2022 Developer Command Prompt :正如标题所说,尽管通过Visual Studio 2022 Developer Command Prompt打开 VS Code 却无法识别cl编译器:
VS 开发者命令提示符

VS Code terminal: VS 代码终端:
在此处输入图像描述

I have tried using VS Code external terminal with我尝试过使用 VS Code 外部终端
%comspec% /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
which did not work.这没有用。

Setting the comspec manualy in the terminal did solve the issue for the terminal instance:在终端中手动设置comspec确实解决了终端实例的问题:
在此处输入图像描述

But the C++ extension is still complaining about cl.exe :但是C++扩展仍然在抱怨cl.exe
cl.exe build and debug is only usable when VS Code is run from the Developer Command Prompt for VS.

I have never used VS Code for C++ before and I don't use windows for development at all so go easy on me.我以前从未使用过 C++ 的 VS Code,而且我根本不使用 windows 进行开发,所以对我来说放轻松。

What could be the reason for the issue and how it can be solved?问题的原因可能是什么以及如何解决?

Visual Studio Developer Command Prompt must be elevated(run as Administrator) in order to correctly open VS Code with the needed permissions.必须提升 Visual Studio 开发人员命令提示符(以管理员身份运行)才能正确打开具有所需权限的 VS Code。

Running Visual Studio Developer Command Prompt as Admin solves the issue.以管理员身份运行 Visual Studio 开发人员命令提示符可解决此问题。

对我有用的一种解决方案是直接进入 C++ 扩展设置并找到编译器路径设置,然后手动将其设置为计算机上的 cl.exe 路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM