Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code compile error - launch.json must be configured

I am trying to compile c# code on windows 7 using visual studio code. I have all the extensions downloaded but am getting this error:

launch: program 'launch: launch.json must be configured. Change 'program' to the path to the executable file that you would like to debug.

I can not figure out how to fix it. This is the line which I believe needs to be changed in the launch.json file, this is what is currently there:

"program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/exam 1.dll"

(exam 1 because that is the name of my .cs file containing my C# code)

When I go into the folder where my .cs file is, this is the whole path:

  • "C:\Users\Kdrumz\Desktop\ObjectOriented\exam 1.cs".

I am very confused. Also, will I always have to do this when using visual studio code? Any help is greatly appreciated!

Using version 1.7.1 of visual studio code

like image 200
Kdrumz Avatar asked Nov 24 '16 18:11

Kdrumz


People also ask

How do you create launch json in Visual Studio Code?

To create a launch.json file, click the create a launch.json file link in the Run start view. If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .vscode folder and added the launch.json file to your workspace.

How do I launch a json file in Visual Studio?

js Apps with Visual Studio Code. Click on Run and Debug in the Activity Bar (⇧⌘D (Windows, Linux Ctrl+Shift+D)) and then select the create a launch. json file link to create a default launch. json file.

How do I change the settings json in Visual Studio Code?

You can open the settings.json file with the Preferences: Open Settings (JSON) command in the Command Palette (Ctrl+Shift+P). Once the file is open in an editor, delete everything between the two curly braces {} , save the file, and VS Code will go back to using the default values.


1 Answers

I fixed it by replacing all the "<>"-styled values in launch.jsonlike this (the project is named 'sample01' in my case):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/sample01.dll",
            "args": [],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false,
            "externalConsole": false
        }
    }
}

As you can see, I only use 1 configuration which is named ".NET Core Launch (console)". This name can be changed and you'll see it when you click on the debug-menu on the far left (the one with the bug-symbol) and take a look at the very top.

Now I entered the complete path of my build-config (which is .NET Core 1.0 in my sample) and it works.

So yes, you would have to do it manually if it is preconfigured with "<>"-elements. If you use dotnet new and then code . to bring up new projects the newer versions of Visual Studio Code will create ready-to-run launch.json now.

like image 56
Alexander Schmidt Avatar answered Oct 13 '22 01:10

Alexander Schmidt