【问题标题】:C# - VS Code - launch:program ... does not existC# - VS Code - 启动:程序...不存在
【发布时间】:2018-09-18 17:31:28
【问题描述】:

我正在尝试在 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 不再像以前那样要求重建资产:

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

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

【问题讨论】:

    标签: c# .net visual-studio-code omnisharp


    【解决方案1】:

    我找到了适合我的解决方案。 我的 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】:

      访问项目文件夹中的 \bin\Debug\netcoreapp3.1(在 VS 中打开)

      进入VS中的launch.json文件:

      替换: "program": "${workspaceFolder}/bin/Debug//.dll",

      使用: "程序": "${workspaceFolder}/bin/Debug/netcoreapp3.1/CSharp.dll",

      在某些情况下,该项目称为CSharp。小心。

      【讨论】:

        【解决方案3】:

        我遇到了同样的错误。调试器在${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",
        ...
        

        我能够毫无问题地调试应用程序。

        【讨论】:

          【解决方案4】:

          既然你有 :".dll" 用“”标记,这意味着你给它一个值。 最简单的方法是在 VSCode 中打开项目并使用 find&replace 替换: 使用您的项目名称,我相信它:根据 .dll 名称进行“测试”

          【讨论】:

          • 正如我的帖子中提到的:如果我手动将 launch.json 中的路径从 "${workspaceFolder}/bin/Debug//.dll”到“${workspaceFolder}/bin/Debug/netcoreapp2.1/test.dll”,它确实可以工作,但是,在没有替换launch.json中的任何内容之前它工作正常
          • 通常情况下,只有在项目创建期间 VSCode 停止响应时才会发生这种情况。
          • VS Code 在任何时候都不会停止响应。另外,我尝试过多次创建新应用程序,但还是一样。
          • @GiedriusElectrum 我在升级到较新版本的 .netcore 时发生了这种情况。您的应用将编译到 bin 文件夹中的不同目录,您需要在 launch.json 中指向该新目录。
          【解决方案5】:

          像这样配置你的 Launch.json Gist

          并且不需要 Tasks.json ,您可以按 F5 自行构建或配置它,当您按 F5 时应该在默认 shell 中运行哪个命令

          【讨论】:

            【解决方案6】:
            // "program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
               "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/csharp_multi_threads.dll",
            

            您需要根据提示更改程序值

            【讨论】:

              【解决方案7】:

              我切换到 MS Visual Studio,因为我没有找到任何其他解决方案。

              【讨论】:

                【解决方案8】:

                -右键单击项目名称并单击在资源管理器中显示 - 在文件夹名称后复制资源管理器中的 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 - 在 Launch.json 中粘贴“程序”:“” -点击调试就OK了

                【讨论】:

                  【解决方案9】:

                  在 launch.json 中,替换:

                  “程序”:“${workspaceFolder}/Api/bin/Debug/netcoreapp3.1/Api.dll”,

                  与:

                  “程序”:“${workspaceFolder}/Api/bin/linux/Debug/netcoreapp3.1/Api.dll”

                  因为我是在 Linux 机器上运行代码,所以我应该提供 Linux 文件夹的路径

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2021-01-26
                    • 1970-01-01
                    • 2023-03-28
                    • 1970-01-01
                    • 2019-12-17
                    • 1970-01-01
                    相关资源
                    最近更新 更多