You are not logged in.

#1 2020-12-15 08:35:06

grisu
Member
Registered: 2020-12-07
Posts: 14

[SOLVED] .NET Core, unable to debug in Visual Studio Code

Hi there,

I'm currently trying to develop C# software with .NET Code in Visual Studio Code. I succeeded to run the code via dotnet run, but it won't work when I try to debug the program from within Visual Studio Code.

To keep things simple, I just created a new Hello World console project:

$ dotnet new console
$ dotnet run
Hello world!

When I open the folder in VSCode

$ code .

the C# extension asks the question "Required assets to build and debug are missing from 'consoletest'. Add them?" where I answer yes. So now I have a launch.json

{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
   "version": "0.2.0",
   "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/bin/Debug/net5.0/consoletest.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

and a tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/consoletest.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/consoletest.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "${workspaceFolder}/consoletest.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

and the corresponding entry in VSCode's debugging section. When I now start the debugging session (by pressing the play button or F5), the code gets compiled and I see in the VSCode's terminal:

> Executing task: dotnet build /home/grisu/consoletest/consoletest.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <

Microsoft (R)-Build-Engine, Version 16.8.0+126527ff1 für .NET
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

  Wiederherzustellende Projekte werden ermittelt...
  Alle Projekte sind für die Wiederherstellung auf dem neuesten Stand.
  consoletest -> /home/grisu/consoletest/bin/Debug/net5.0/consoletest.dll

Terminal will be reused by tasks, press any key to close it.

Right after that VSCode switches to the Debug Console tab, showing only

-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------

And that's it. No "Hello World!" and my breakpoint in the Main method is not hit.

I also tried

$ dotnet clean

before debugging and the file ./bin/Debug/net5.0/consoletest.dll is NOT created when I start debugging via VSCode.
These steps work flawless with .NET 5.0 under Windows 10, so it might be a problem with my machine.

I use the packages

dotnet-host-bin
dotnet-targeting-pack
dotnet-runtime-bin
dotnet-targeting-pack-bin
dotnet-sdk-bin
aspnet-runtime-bin

from AUR after I tried the same with the packages

dotnet-runtime
dotnet-sdk

without success.

$ dotnet --info
.NET SDK (gemäß "global.json"):
 Version:   5.0.101
 Commit:    d05174dc5a

Laufzeitumgebung:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.101/

Host (useful for support):
  Version: 5.0.1
  Commit:  b02e13abab

.NET SDKs installed:
  5.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

I found two other unlucky guys on Stack Overflow with the same problem (Debugging dotnet (core) not working in vscode (linux) and How to debug asp.net core 3.1 using vscode in linux(ubuntu)) without a solution.

As I don't want to stick to Windows for software development, I would be really, really happy if we cant find the solution together.

Last edited by grisu (2020-12-15 09:03:07)

Offline

#2 2020-12-15 08:47:06

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [SOLVED] .NET Core, unable to debug in Visual Studio Code

Do you use vscode from the AUR or the open source "code" from community? The dotnet debugger is only allowed to run with the microsoft vscode build from the AUR

Edit: You may be able to use netcoredbg by samsung if you want to use open source: https://github.com/VSCodium/vscodium/issues/82

Last edited by progandy (2020-12-15 08:49:17)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#3 2020-12-15 09:02:54

grisu
Member
Registered: 2020-12-07
Posts: 14

Re: [SOLVED] .NET Core, unable to debug in Visual Studio Code

I was using the open source code and that was the problem.
As I just saw, the problem is also described on the VS Code Wiki page, but I just looked over and over the .NET Code Wiki page.
The netcoredbg package is broken right now (404 on the github server), so I tried the Microsoft branded version of VS Code. Now it works like a charm.
Thank you very much!

Offline

Board footer

Powered by FluxBB