Visual Studio Code compile error - launch.json mus

2020-04-02 07:43发布

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

3条回答
家丑人穷心不美
2楼-- · 2020-04-02 08:23

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.

查看更多
在下西门庆
3楼-- · 2020-04-02 08:28

1) Open your project directory/folder in Explorer (windows) or Finder (Mac).

2) Go to bin/Debug/netcoreapp{version}/{projectName}.dll and make sure you copy the absolute and complete path of the main project DLL and put it as a value to all program elements inside your launch.json.

Make sure to change all program elements in all sections in launch.json (console/web)

{
...
...
"program": "/Users/msoliman/Workspace/ProjectName/bin/Debug/netcoreapp1.0/MyProject.dll",
...
...
}
查看更多
一夜七次
4楼-- · 2020-04-02 08:35

For anyone still hitting this issue:

  1. Open up your Program.cs file before starting to debug.
    • Opening any .cs file fires the C# extension.
  2. The extension will then ask if it can load build assets . Hit Yes.
    • It may take a few seconds to load Omnisharp
    • It only asks this if the launch.json and tasks.json haven't already been added to the project.
  3. Then the extension will configure your launch.json and tasks.json for you.

For those interested there is an issue tracking this behavior.

查看更多
登录 后发表回答