2

I have a workspace open in VS Code with multiple nested subdirectories for different projects. When I go to the Debugging Run in the sidebar and click on create a launch.json file a popup prompt appears to Select a workspace folder to create a launch.json file in or add it to the workspace config file with the options in the dropdown being the 1. current open workspace 2. workspace. When I select (1) and add the required configurations to the launch.json file the .vscode/launch.json is located in the root directory of the workspace and NOT the root directory of the project (in this case a React Native project) and when running the debugger I get the following error:

An error occurred while attaching debugger to the application. Seems to be that you are trying to debug from within directory that is not a React Native project root. If so, please, follow these instructions: https://github.com/microsoft/vscode-react-native#customization (error code 604) (error code 1410)

How can I configure the launch.json file for a specific project in a VS Code workspace, rather than for the entire workspace?

3
  • If I understand correctly, you can create a .vscode folder in each project manually, and add your launch.json there for each project. Perhaps I misunderstand your question though? Commented Nov 22, 2020 at 9:32
  • the issue remains, as in the Debugger menu it does not pick up that you are currently working on a given project in the workspace, so it does not see that workspace_dir/project_dir/.vscode/launch.json file Commented Nov 22, 2020 at 10:14
  • .vscode in a subfolder is not recognized by VSC. Use MultiRoot Workspace Commented Nov 22, 2020 at 10:18

2 Answers 2

4

You can work with a MultiRoot Workspace.

  • Open a Workspace with: File | Open Folder
  • Add Workspaces with: File | Add Folder to Workspace
  • Save the MultiRoot Workspace: File | Save Workspace As

Next time you open this MultiRoot Workspace with: File | Open Workspace

Now each Workspace folder can have its own .vscode folder with launch.json and tasks.json.

When you now open a launch.json you can add Configurations by hand or with the Add Configuration... button in the lower right.

In the Debug Bar you can now select a Launch config from any of the Workspaces.

It is also possible to add the different launch configurations for the sub folders of a Workspace, in case you need to launch multiple configs (server and client) but then you need to set the parameters yourself like cwd.

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

5 Comments

I already have a vs code workspace with multiple projects in it, the issue is opening that workspace and selecting a project at any moment to debug.
@AgentAnon Create .vscode/launch.json and add your configs needed, then select the one you want from the drop down in Debug Bar. Read the doc on VSC Debugging
I did create a .vscode/launch.json file in the root dir of the project, and I cannot select the config whilst the workspace is open, only when I open the project dir itself. Is there a difference between a code-workspace and a MultiRoot Workspace?
If your projects were set up as multi-roots properly then this extension might be of interest: marketplace.visualstudio.com/… You can launch any debug config from any root folder.
code-workspace === MultiRoot Workspace. It depends how many folders you have specified in this code-workspace file, use a different editor to open this json file. It can be 1 or more
0

Add C# extension from Microsoft. Post that open any cs file. It will install C# dependencies.The you will get a pop up enter image description here

Click yes. Both tasks.json and launch .json are created.

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.