17

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

1

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It appears if you have multiple projects open then it won't be able to run any of the others unless you're running the first generated (dotnet new) one. Opening up a 'secondary' project directly solved my issue though, a bit of a pain but it will do until I find a better way.
1

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.

Comments

0

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",
...
...
}

Comments

0

If the pop-up shows like launch.json when u click on run with debugging for HTML file firstly u will run ng serve in cmd.

When it compiled successfully then u can see localhost:4200 like URL u have to match that URL in launch.json file.

Don't close the cmd it should be run in the background.

Comments

0

I get this annoying error from time to time for no apparent reason. Think it is a hard to find bug in VS Code C# environment (specifically in the OmniSharp extension) which triggers from time to time, and messes up the launch files in the .vscode folder. It may be triggered depending on how you create a C# project, seems that part of OmniSharp ceases to work and this triggers the problem. Looking closely in the OmbiSharp output console I do sometime get a note, that launch.json is locked, and thus cannot be modified, but most often OmniSharp fails without any message, I suppose there are various possible causes.

Anyway, I can always fix it by renewing the launch config files like this:

(1) In Code Explorer, delete the .vscode folder (2) Open the Command Window (Shift-Ctrl-P) and execute Ominsharp: Restart Omnisharp (3) Move the focus to any .cs file (if you have only one, move the focus to any other file and back)

After you focus the .cs file, down in the right corner of Visual Studio Code, a message must pop up telling you that "Required assets to build and debug are missing", hit "Yes" to get .vscode and its contents re-created. If you don't get the message, find out why not, note, it can be turned off and on through settings.

Run your project, it should re-create the .vscode folder and its files and should run fine from now on.

Note that there are variuos tipps on the net which tell you to modify launch.json or tasks.json by hand to get rid of the problem. While this may help if you are patient enough to do all the necessary changes by hand every time, this is a poor workaround. If OmniSharp does its job correctly, its doing all the modifications, if the modifications fail, clear the files and restart OmniSharp instead of messing with the files by hand.

Verified with VS Code 1.61.0 and OmniSharp 1.23.16 (latest versions as of Oct 2021)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.