C# - VS Code - launch:program ... does not exist

13

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

这里输入图片描述

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

${workspaceFolder}/bin/Debug/insert-target-framework-here/insert-project-name-here.dll

收件人:

"${workspaceFolder}/bin/Debug/netcoreapp2.1/test.dll"

然而,它确实可以工作,但是之前在我手动输入路径之前它也能正常工作。另外,我注意到VS Code不再像以前那样询问重新构建资产:

enter image description here

我已尝试了以下方法:

卸载了VS Code、 .NET Core 2.1,从 %USER%\.vscode\ 中删除了VS Code扩展文件夹,重新安装了VS Code,然后再安装.NET Core 2.1和C#扩展(C# for Visual Studio Code (powered by 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"
    }

还有 tasks.json 文件:

    "version": "2.0.0",
"tasks": [
    {
        "label": "build",
        "command": "dotnet build",
        "type": "shell",
        "group": "build",
        "presentation": {
            "reveal": "silent"
        },
        "problemMatcher": "$msCompile"
    }
]
}
10个回答

13

我找到了一个对我有效的解决方案。我的VS Code也出现了同样的错误提示,我用以下方法解决了它:

- Press the combination Ctrl + Shift + P
- Restart Omnisharp
- Then it asks if you want to add missing files for build.
- Click Yes.

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

希望它也能为你工作!


2
请到你在VS中打开的项目文件夹下的\bin\Debug\netcoreapp3.1目录下进行访问。
在VS中前往launch.json文件:
将以下内容:
"program": "${workspaceFolder}/bin/Debug//.dll",
替换为:
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/CSharp.dll",
请注意,我的项目名称叫做CSharp

2

我曾经遇到过同样的错误。调试器在${workspaceFolder}/bin/Debug/netcoreapp3.1/myApp.dll中寻找.dll文件,但实际上该文件位于${workspaceFolder}/bin/MCD/Debug/netcoreapp3.1/tradeAppl.dll

更改launch.json文件如下:

...
"program": "${workspaceFolder}/bin/MCD/Debug/netcoreapp3.1/tradeAppl.dll",
...

我能够无障碍地调试应用程序。


0

由于您在".dll"标签中使用了"<"和">",这意味着您已经给它赋值了。 最简单的方法是在VSCode中打开项目,并使用查找和替换功能将:

替换为您的项目名称,我相信它应该是:"test",根据.dll文件名


1
如我在帖子中提到的:如果我手动将launch.json中的路径从"${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll"更改为"${workspaceFolder}/bin/Debug/netcoreapp2.1/test.dll",它确实可以工作,但之前没有替换launch.json中的任何内容也能正常工作。 - RollerMobster
通常情况下,这种情况发生在使用VSCode创建项目时出现无响应的情况。 - CMoussalli
VS Code 在任何时候都不会停止响应。此外,我已经尝试创建新的应用程序多次,但仍然是同样的情况。 - RollerMobster
@GiedriusElectrum 我在升级到较新版本的 .netcore 时遇到了这个问题。你的应用程序将编译到 bin 文件夹中的不同目录中,你需要在 launch.json 中指向那个新目录。 - jjr4826
在 Ubuntu 中遇到了类似的问题。使用以下命令启动 VS Code:code --no-sandbox - Dennis Kabugua

0

像这样配置您的Launch.json Gist

无需Tasks.json,您可以按F5键进行构建或自行配置默认shell中按下F5时应运行哪个命令


0

这可能是由于 launch.json 文件中 program 属性指向的 dll 路径有问题。

在我的情况下,版本升级后,它仍然包含旧的 .net core 框架版本。


0

-右键单击项目名称,然后单击“在资源管理器中显示” -复制文件夹名称后的资源管理器中的URL 例如,我的文件夹地址是 D:\IOT\Projects\LWSIOT_WebApiWM2\LWSIOT_WebApiWM2\LWSIOT_WebApiWM2\bin\Debug\netcoreapp3.1\LWSIOT_WebApiWM2.dll 并在Launch.json中: ${workspaceFolder}/LWSIOT_WebApiWM2/LWSIOT_WebApiWM2/bin/Debug/netcoreapp3.1/LWSIOT_WebApiWM2.dll -将其粘贴到“Program”:“<Your_Address>”中的Launch.json中 -单击“调试”,一切都没问题


0
在 launch.json 中,将以下内容替换为:
"program": "${workspaceFolder}/Api/bin/linux/Debug/netcoreapp3.1/Api.dll"
原先的代码是:
"program": "${workspaceFolder}/Api/bin/Debug/netcoreapp3.1/Api.dll"
因为我在 Linux 机器上运行代码,所以应该提供 Linux 文件夹的路径。

0

我转而使用MS Visual Studio,因为我没找到其他的解决方案。


在Ubuntu中遇到了类似的问题。使用以下命令启动VS Code:code --no-sandbox。 - Dennis Kabugua

0
// "program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
   "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/csharp_multi_threads.dll",

你需要根据提醒更改程序的值。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接