【问题标题】:Visual Studio Code does not debugVisual Studio Code 无法调试
【发布时间】:2020-03-26 15:14:47
【问题描述】:

我使用 Visual Studio Code 已经有一段时间了,但我无法调试任何 .NET 和 .NET Core 应用程序。我试过启动,附加到进程,但是当我运行任务时它什么也没做。 有一次,它确实将条的颜色从蓝色变为橙色一秒钟,然后又变回蓝色,所以我猜它试图做些什么,但即使在那之后也没有任何反应。我的同事们从来没有遇到过这个问题,这意味着我的编辑器一定有问题。 我也尝试过重新安装、删除配置、安装不同的版本,但总是会发生同样的事情。我现在很茫然,所以如果有人知道如何解决这个问题,我会很高兴。

编辑: 我已尝试重新安装omnisharp 扩展程序,但仍然无法正常工作。

这是我的 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": "build",
        "program": "${workspaceFolder}/WebAPI/bin/Debug/netcoreapp2.2/WebAPI.dll",
        "args": [],
        "cwd": "${workspaceFolder}/WebAPI",
        "stopAtEntry": false,
        "serverReadyAction": {
            "action": "openExternally",
            "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
        },
        "env": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "sourceFileMap": {
            "/Views": "${workspaceFolder}/Views"
        }
    },
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command:pickProcess}"
    }
]}

【问题讨论】:

  • 尝试安装或重新安装omnisharp扩展。并分享您的启动配置。

标签: asp.net asp.net-core visual-studio-code vscode-settings vscode-debugger


【解决方案1】:

我通常做的是通过导航.csproj 或.sln 所在的目录,使用终端打开我正在处理的项目。然后在终端中用code .打开VS Code。

从那里,尝试按F5 键启动调试器,或者通过左侧导航树单击开始调试。

调试器应该注意到您没有任何启动设置,并且应该提示您尝试调试的语言。

如果是这种情况,请选择 .NET Core。

应该在当前目录中创建一个.vscode 文件夹,其中包含一个名为launch.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": "build",
            "program": "${workspaceFolder}/PearlMills.API/bin/Debug/netcoreapp2.2/PearlMills.API.dll",
            "args": [],
            "cwd": "${workspaceFolder}/PearlMills.API",
            "stopAtEntry": false,
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

最后,点击F5 启动调试器,程序应该从launch.json 文件中的启动设置开始。

如果这些步骤不起作用,请尝试删除创建的 .vscode 文件夹和/或禁用所有 VS Code 扩展。然后再做一次这个序列。可能会有一个 VS Code 扩展让您难以调试。

您也可以尝试创建一个 Hello World 应用程序,如果仍然无法启动,请再次尝试这些步骤。

还要确保您的计算机上安装了 .NET SDK 和运行时。 终端中的dotnet --info 应该会显示您需要知道的所有内容。

【讨论】:

    【解决方案2】:

    尝试在launch.json 文件中进行以下更新:

     "env": {
                    "ASPNETCORE_ENVIRONMENT": "Development",
                    "ASPNETCORE_URLS": "http://localhost:4000"
                },
    

    为重定向添加了ASPNETCORE_URLS。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-18
      • 1970-01-01
      • 2021-02-01
      • 1970-01-01
      • 2020-06-09
      • 2022-06-24
      • 2016-12-23
      • 1970-01-01
      相关资源
      最近更新 更多