VS Code调试Azure Functions报错-Command未识别,手动运行func host start正常
问题原因
该错误是VS Code执行调试任务时,误将PowerShell的启动参数-Command识别为了待执行的命令,本质是项目任务配置或VS Code终端配置异常导致,可按以下步骤修复:
修复步骤
1. 重新生成项目调试配置
删除项目根目录下的.vscode文件夹,按下F1呼出命令面板,执行Azure Functions: 初始化用于VS Code的项目,按照提示完成配置生成后,重新启动调试即可。
如果需要手动核对配置,正确的tasks.json参考如下:
{ "version": "2.0.0", "tasks": [ { "type": "func", "command": "host start", "problemMatcher": "$func-dotnet-watch", "isBackground": true, "dependsOn": "build" }, { "label": "build", "command": "dotnet build", "type": "shell", "group": { "kind": "build", "isDefault": true } } ] }
2. 重置VS Code PowerShell配置
打开VS Code设置(快捷键Ctrl+,),搜索terminal.integrated.profiles.windows,点击「在settings.json中编辑」,确认PowerShell配置无多余启动参数,默认配置如下:
"terminal.integrated.profiles.windows": { "PowerShell": { "source": "PowerShell", "icon": "terminal-powershell" } }
如果配置中存在包含-Command的args字段,直接删除该字段即可。
3. 临时切换终端验证
如果上述操作后仍然报错,可临时将默认终端切换为CMD验证:
- 按下`Ctrl+Shift+``打开终端面板
- 点击终端右上角的下拉箭头,选择「配置默认配置文件」
- 选中「命令提示符」后重启终端,再次启动调试
内容的提问来源于stack exchange,提问作者wilson_smyth
相关产品推荐
相关产品推荐

