如何将VS 2022开发者命令提示符集成到VS Code终端
在VS Code中配置MSVC
cl 编译器终端(设为默认) 配置CMD终端
将Windows Terminal生成的CMD命令拆解为VS Code终端配置格式,解决JSON转义问题:
"terminal.integrated.profiles.windows": { "MSVC CMD (x64)": { "command": "cmd.exe", "args": [ "/k", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\"", "-arch=x64", "-host_arch=x64" ], "icon": "terminal-cmd" } }, "terminal.integrated.defaultProfile.windows": "MSVC CMD (x64)"
说明:JSON中路径的反斜杠需转义为\\,路径字符串用\"包裹,拆分参数避免引号嵌套冲突。
配置PowerShell终端
针对三引号转义问题,提供两种可行方案:
方案1:转义三引号
直接将原命令中的三引号在JSON中转义为\"\"\":
"terminal.integrated.profiles.windows": { "MSVC PowerShell (x64)": { "command": "powershell.exe", "args": [ "-NoExit", "-Command", "&{Import-Module \"\"\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"\"\"; Enter-VsDevShell 0d0637f3 -SkipAutomaticLocation -DevCmdArguments \"\"\"-arch=x64 -host_arch=x64\"\"\"}" ], "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "MSVC PowerShell (x64)"
方案2:改用单引号简化(推荐)
利用PowerShell单引号字面量特性,避免嵌套双引号转义:
"terminal.integrated.profiles.windows": { "MSVC PowerShell (x64)": { "command": "powershell.exe", "args": [ "-NoExit", "-Command", "&{Import-Module 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell 0d0637f3 -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64'}" ], "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "MSVC PowerShell (x64)"
验证配置
重启VS Code后打开终端,选择对应的MSVC终端,输入cl命令,若输出编译器版本信息则配置成功。
内容的提问来源于stack exchange,提问作者maddes8cht
相关产品推荐
相关产品推荐

