空格和括号的问题可以通过以下方式解决转义字符这是插入符号 (^
) 在这种情况下。使用提到的字符在您的相关行settings.json
看起来像:
"terminal.integrated.shellArgs.windows": [
"/k",
"C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat"
],
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
这种方法的问题与您添加路径时遇到的问题相同vcvars64.bat
to the PATH
变量,即 Visual Studio Code 将append的价值观"command"
and "args"
从你的tasks.json
前缀为/d
and /c
的值"terminal.integrated.shellArgs.windows"
当执行你的任务时。这导致vcvars64.bat
将得到提到的值作为参数而不是cmd.exe
。标记为的错误[ERROR:vcvarsall.bat]
出现的原因是拒绝参数附加到了错误的地方。
您可以通过为您的任务指定带有适当参数的 shell 来解决此问题,如下所示:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"shell": {
"executable": "C:\\Windows\\System32\\cmd.exe",
"args": [
"/d", "/c",
"C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat",
"&&"
]
}
},
"tasks": [
{
"label": "Build Test",
"type": "shell",
"command": "cl",
"args": [
"/MDd",
"/W4",
"/EHsc",
"/ZI",
"/std:c++11",
"/Od",
"/Fe:${workspaceFolder}/Debug/test.exe",
"/Fd:${workspaceFolder}/Debug/",
"/Fo:${workspaceFolder}/Debug/",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Build Release",
"type": "shell",
"command": "cl",
"args": [
"/MD",
"/W4",
"/EHsc",
"/std:c++11",
"/O2",
"/Fe:${workspaceFolder}/Release/test.exe",
"/Fd:${workspaceFolder}/Release/",
"/Fo:${workspaceFolder}/Release/",
"main.cpp"
]
}
]
}
另一种方法是离开"terminal.integrated.shellArgs.windows"
空,即不向cmd.exe
in the settings.json
,然后改变你的tasks.json
如下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"env": {
"build": "C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat && cl"
}
},
"tasks": [
{
"label": "Build Test",
"type": "shell",
"command": "%build%",
"args": [
"/MDd",
"/W4",
"/EHsc",
"/ZI",
"/std:c++11",
"/Od",
"/Fe:${workspaceFolder}/Debug/test.exe",
"/Fd:${workspaceFolder}/Debug/",
"/Fo:${workspaceFolder}/Debug/",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Build Release",
"type": "shell",
"command": "%build%",
"args": [
"/MD",
"/W4",
"/EHsc",
"/std:c++11",
"/O2",
"/Fe:${workspaceFolder}/Release/test.exe",
"/Fd:${workspaceFolder}/Release/",
"/Fo:${workspaceFolder}/Release/",
"main.cpp"
]
}
]
}
调用的必要性vcvars64.bat
如果从 Visual Studio 的开发人员命令提示符启动 Visual Studio Code,则可以省略每个构建之前的内容。为了方便起见,您可以使用以下目标创建快捷方式:
cmd /d /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" && start /b code
这将使开发人员命令提示符保持打开状态,可以根据需要关闭它。