【发布时间】:2022-12-03 13:12:50
【问题描述】:
我正在使用 ASP.NET MVC 开发 Web 应用程序。要运行它,我使用以下 shell 命令:
dotnet restore ProjectDirectory
接着
dotnet run --project ProjectDirectory
如果我在我的命令 shell 中运行它们,一切正常。但是我的代码编辑器是 VS Code,所以我想让它在集成终端中运行这些命令。我已经在其文件launch.json 和tasks.json 中配置了它的行为:
// launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "restore",
"program": "C:/Windows/System32/dotnet.exe", // The directory separation char is / in this attribute (not \)
"args": ["run", "--project", "${workspaceFolder}"],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyWebApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/MyWebApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/MyWebApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
// Here is my preLaunchTask
{
"label": "restore",
"command": "dotnet",
"type": "process",
"args": [
"restore",
"${workspaceFolder}"
],
"problemMatcher": "$msCompile"
}
]
}
配置后我试了一下。我按了F5。集成终端打开,并尝试运行
dotnet restore ProjectDirectory
但随后它显示了以下错误消息:
终端进程启动失败:启动时出现本机异常(CreateProcess failed)
我试过的
我打开 VS Code 文档并进行了一些研究。我只找到了一个关于排除集成终端故障的page。
我尝试了上面故障排除页面中的所有建议。他们没有帮助我。
上网冲浪(包括 Stack Overflow)。我没有找到有用的页面(不包括上面描述的故障排除页面)。
现在我问我自己的问题。
【问题讨论】:
-
苹果系统?视窗?德比安?
-
@Pieterjan Windows
-
@SNBS 检查 VSCode 的 settings.json。它是否正确设置了以下行 "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe"
-
@SNBS 您是否尝试过使用“以管理员身份运行”选项打开 VSCode?如果没有,请尝试并让我知道它的作用。
-
@ChinmayT 是的,它始终以管理员身份运行。也许在两个小时后我会花时间查看
terminal.integrated.shell.windows并让你知道。
标签: visual-studio-code vscode-debugger vscode-tasks