C# - VS Code - 启动:程序...不存在

Gie*_*666 5 .net c# omnisharp visual-studio-code

我试图在 VS Code 中调试一个简单的“Hello world”应用程序,但是,当我按 Ctrl + F5 时,它给了我以下错误:

在此处输入图片说明

如果我手动更改 launch.json 中的路径:

${workspaceFolder}/bin/Debug/insert-target-framework-here/insert-project-name-here.dll
Run Code Online (Sandbox Code Playgroud)

到:

"${workspaceFolder}/bin/Debug/netcoreapp2.1/test.dll"
Run Code Online (Sandbox Code Playgroud)

它确实有效,但是在没有我手动输入路径的情况下它可以正常工作之前。另外,我注意到 VS Code 不再像以前那样要求重建资产:

在此处输入图片说明

到目前为止,我已经尝试了以下方法:

卸载 VS Code,然后是 .NET Core 2.1,从 %USER%\.vscode\ 中删除 VS Code 扩展文件夹,重新安装 VS Code,然后是 .NET Core 2.1,然后是 C# 扩展(C# for Visual Studio Code(供电)由 OmniSharp))。

当 VS Code 启动时,它确实成功下载了“OmniSharp”包,但是当我打开 C# 文件时仍然没有提示重建资产。调试给出了与以前相同的问题。

这是launch.json:

"version": "0.2.0",
"configurations": [
    {
        "name": ".NET Core Launch (console)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
        "args": [],
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "stopAtEntry": false,
        "internalConsoleOptions": "openOnSessionStart"
    }
Run Code Online (Sandbox Code Playgroud)

和tasks.json:

    "version": "2.0.0",
"tasks": [
    {
        "label": "build",
        "command": "dotnet build",
        "type": "shell",
        "group": "build",
        "presentation": {
            "reveal": "silent"
        },
        "problemMatcher": "$msCompile"
    }
]
}
Run Code Online (Sandbox Code Playgroud)

小智 9

我找到了一个对我有用的解决方案。我的 VS Code 给了我同样的错误信息,我修复它的方法是:

- Press the combination Ctrl + Shift + P
- Restart Omnisharp
- Then it asks if you want to add missing files for build.
- Click Yes.
Run Code Online (Sandbox Code Playgroud)

在此之后,我能够调试我的应用程序。

希望这对你有用!