【问题标题】:The terminal process failed to launch: A native exception occurred during launch (VS Code Integrated Terminal)终端进程启动失败:A native exception occurred during launch (VS Code Integrated Terminal)
【发布时间】: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)

我试过的

  1. 我打开 VS Code 文档并进行了一些研究。我只找到了一个关于排除集成终端故障的page。

  2. 我尝试了上面故障排除页面中的所有建议。他们没有帮助我。

  3. 上网冲浪(包括 Stack Overflow)。我没有找到有用的页面(不包括上面描述的故障排除页面)。

  4. 现在我问我自己的问题。

【问题讨论】:

  • 苹果系统?视窗?德比安?
  • @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


【解决方案1】:

看起来问题出在 tasks.json 文件中的还原任务中的 args。 restore 命令不使用 --project 标志,因此您应该将其从 args 数组中删除。

您的恢复任务应如下所示:

{
    "label": "restore",
    "command": "dotnet",
    "type": "process",
    "args": [
        "restore",
        "${workspaceFolder}"
    ],
    "problemMatcher": "$msCompile"
}

您还应确保launch.json 文件中的preLaunchTask 属性设置为“恢复”。

"preLaunchTask": "restore",

进行这些更改后,尝试再次运行您的项目并查看问题是否已解决。

【讨论】:

  • 没有帮助。同样的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-09
  • 1970-01-01
  • 1970-01-01
  • 2021-12-31
  • 2021-08-30
  • 2021-09-12
  • 2021-04-21
相关资源
最近更新 更多