Visual Studio Code debugger: launch.json The property 'program' is invalid

Avi Kenjale picture Avi Kenjale · May 9, 2016 · Viewed 15.2k times · Source

1. Setup: I have installed Visual Studio code on My Ubuntu and installed .NET Core and Mono.

2. Intial Configuration: I created a simple demo app running notnet restore and dotnet run. This simply works fine and display "Hello World!" on terminal.

3. Extension: To debug this, I installed extension of OmniSharp. and then using "Debugger" option of Visual Studio Code, I added launch.json & task.json.

4. launch.json (Only showing configuration section):

....
"configurations": [
    {
        "name": ".NET Core Launch (console)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceRoot}/bin/Debug/netstandardapp1.5/hwAppCore2.dll",
        "args": [],
        "cwd": "${workspaceRoot}",
        "stopAtEntry": false
    }    
....

5. Now, when running from terminal it works fine, however when try to debug using option .NET Core Launch (console) I am getting following error:

"launch: The property 'program' is invalid. '/home/ak/dotnet_core/hwAppCore2/bin/Debug/netstandardapp1.5/hwAppCore2.dll' is a library (.dll), not a program."

I also followed one of Channel 9 demo, and there also I can see hwapp.dll configured for program property of launch.json

I am not sure, am I missing anything to configure?

Answer

brichins picture brichins · Sep 19, 2016

There are several hoops you have to jump through to get VS Code debugging .NET Core websites. The relevant steps (from this blog post walkthrough) are:

  • Install C# extension and the .NET Debugger (Ctrl + Shift + P, "Download .NET Core Debugger")
  • Open your project folder - it should prompt you to add build tasks
    • (creates .vscode > tasks.json)
  • Open the Debug tab from the sidebar, click the 'Settings' button, and choose ".NET Core"
    • (creates .vscode > launch.json) with 3 configurations - "console", "web", and "attach".
  • Open the launch.json file and edit the "web" configuration's program value - replace the <> placeholders with your specific values (e.g. netcoreapp1.0 and MyProject.dll).
    • (This is the step the OP needed to do)
    • For some reason VS Code doesn't handle the placeholders for web projects... I haven't been able to find any documentation / explanation why yet
  • Edit the project.json file - under buildOptions, add "debugType" : "portable"
  • Run dotnet restore on your project to get the latest packages
  • Start debugging!