【问题标题】:Visual Studio Code C# "Run Without Debugging" errorVisual Studio Code C#“在不调试的情况下运行”错误
【发布时间】:2021-05-24 20:01:26
【问题描述】:

我在 Ubuntu 18.04 上安装了 Visual Studio Code 1.56.2 来开发 Python。

几天前,我安装了“.NET Core for C# coding on Linux”,因此我可以使用 Visual Studio Code 编写 C#。

当我尝试运行“Program.cs”(hello world)应用程序时,我收到一个弹出窗口并显示错误“您没有用于调试 C# 的扩展。我们应该在 Marketplace 中找到 C# 扩展吗?”

我已经安装了“C# for Visual Studio Code(由 OmniSharp 提供支持)。Microsoft”,如下所示:

这是我的工作区结构:

如果能帮我解决这个问题,我将不胜感激。

【问题讨论】:

标签: c# visual-studio-code


【解决方案1】:

确保在项目/解决方案根目录中名为 .vscode 的文件夹中同时拥有 launch.jsontask.json

如果你不这样做,你可以去菜单Run>Add Configuration...

它应该自动创建文件,但如果你不能,这里是这些文件内容的示例(你需要调整到你的本地 fylesistem/project/version 值)

tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "shell",
            "args": [
                "build",
                // Ask dotnet build to generate full paths for file names.
                "/property:GenerateFullPaths=true",
                // Do not generate summary otherwise it leads to duplicate errors in Problems panel
                "/consoleloggerparameters:NoSummary"
            ],
            "group": "build",
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

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 (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/bin/Debug/net5.0/net.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

【讨论】:

  • 感谢您的详细回复。我必须手动创建一个launch.json 文件,如您所展示的那样才能通过此错误。现在我收到此错误:“找不到调试类型'coreclr'的调试适配器描述符(扩展可能无法激活)”。这是屏幕截图fortitudevolution.com/VisualStudioCode/images/…
  • 我刚刚按照这篇文章stackoverflow.com/questions/58257448/… 中的建议卸载并重新安装了 C# 扩展程序,现在我收到此错误“启动程序”~/MyApp/bin/Debug/net5.0/net.dll'不存在。
  • 我刚刚开始工作!必须将 launch.json “program” 行更改为指向 MyApp.dll,例如 "program": "${workspaceFolder}/bin/Debug/net5.0/MyApp.dll",感谢@Rodriguo 的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-29
  • 2023-03-11
  • 1970-01-01
  • 2011-12-19
  • 1970-01-01
  • 2019-03-09
相关资源
最近更新 更多