specifying vscode tasks.json location - visual-studio-code

When I press F9 in vscode it runs a task from C:\Users\James\AppData\Roaming\Code\User\tasks.json
That is, no matter what folder or workspace I have open, the same task.json file is always used.
How do I get vscode to use a task.json that is specific to the open workspace or folder?
The docs say that the tasks.json file should be in .vscode/ and I have placed it there, but it is ignored. I guess I accidently modified a setting that controls where this file should be, but I cannot find it to undo the change.
Clicking menu Terminal | Configure tasks also takes me to C:\Users\James\AppData\Roaming\Code\User\tasks.json

Workaround.
Delete C:\Users\James\AppData\Roaming\Code\User\tasks.json
Create new workspace
Clicking menu Terminal | Configure tasks

Related

Disabling VSCode Workspace Auto Opening

I'm working with a directory which looks like the following
packageName/src/packageName.
When I attempt to open the high level folder, VSCode automatically opens the lower level folder as a workspace which is incredibly frustrating. I've attempted to modify the "path" setting in the workspace settings file, but I had no luck- on an attempt to reopen the desired folder, the path parameter value was automatically changed back. How can I disable this functionality?

Where is the 'launch.json' file in Visual Studio Code?

The launch.json file should be inside the .vscode folder, but it is not present there.
How can I get this file so that I can modify the configurations?
As described in the Launch Configurations section of the Visual Studio Code documentation:
VS Code keeps debugging configuration information in a launch.json
file located in a .vscode folder in your workspace (project root
folder) or in your user settings or workspace settings.
To create a launch.json file, click the create a launch.json file link
in the Run start view.
As of Visual Studio Code 1.56:
Once that's created, it should now be available under your workspace's .vscode folder.
Click on the debug side bar to open the debugging options. Then either the cog icon at the top, or the create a launch.json file link below the big blue button. If the launch.json file is present, it will open it otherwise it will generate one.
Warning: if you try to create an empty one (or one with an invalid content), trying to get to that file through the "Create a launch.json file" would not do anything.
See issue 133327.
That will be fixed with VSCode 1.61 (Sept. 2021): at least, that existing file will be opened when you click on "Create a launch.json file".

Pressing F5 is not working in VS code to open new window for debugging my custom theme

I have created a new custom theme using the Yoeman theme generated and now when I pressed on F5 to open a new Host Extension window of the custom theme it is actually showing me to select environment?
I have managed to open a new Extension development window by the following step which is not the ideal way to do it but helped me to run it.
I have selected the chrome (preview) option which will create a .vscode folder in your workspace and will have one file launch.json.
In your project directory, you will also have a .vscode folder and launch.json file inside it. So, I have copied the content of launch.json and pasted it in the workspace launch.json file.
I don't know the reason how it is get solved with that but happily, I managed to open the new Extension Development Host window.
The reason for not showing up the Extension Development Host window by pressing F5 in the first place is because my VS code workspace is not inside the project directory. The project directory contains the setup for launching the Extension Development Host window in launch.json. So, If I want to suggest then I would say that VS code workspace needs to be inside the project folder directory.
You must open the project root directory not the directory that wraps project root.
In my case, test1 was the root directory.
DO NOT
DO

How to create a workspace

How do we create a workspace in Visual Studio Code?
I see File menu commands to open, add a folder to and save a workspace, but nothing to create one.
The questions How can I create a workspace in Visual Studio Code? and How can I create a Visual Studio Code Python workspace? are specific to Python. I am asking how to create a generic workspace.
The question What is a 'workspace' in Visual Studio Code? provides some explanation of what they are, but it is not clear how to create them.
I had your same question, but the answer is simple, you don't. There is no need to start a blank workspace. To start on a new project use Open Folder from the File menu: navigate to the project, create a folder if needed, and then select the folder. You are now working on any files within that folder as if it were a workspace. If you leave and open another folder or workspace with files still open in editors, those files will be open when you open that folder again. Visual Studio Code making things work effortlessly! Until you do something that specifically requires a workspace you don't have to save it. If you save a workspace with no settings changed to the root folder here's what it looks like: {"folders": [{"path": "."}],"settings": {}}. That's it. The open editors are saved internally regardless of whether you saved as workspace. Starting by saving a blank workspace is like having an empty file cabinet in your office. VSCode will inform you if you ever need that and you can save a workspace then.
I finally had a chance to use VSC on a Mac. The difference on a Mac is
that Open File and Open Folder are under the same general Open
command (apparently because Macs use the same browser to select files and folders). Just use that to Open a folder, and open files in that folder workspace using the VSC explorer. All this still applies. The folder is the workspace.
You only need to save that workspace if you want to Add Folder to Workspace (in which case VSC will prompt you to save your multiroot workspace if you exit, or if you want to save settings specific to your project folder (though you can do that without a workspace using a settings json in a .vscode folder within). Even then VSC will auto save workspace settings for the folder internally when you haven't explicitly made the project folder a workspace.
Do you need a workspace and the extra .code-workspace file involved? If you have multiple root folders it's certainly nice to open the workspace and have those all there in your next session. If it's just for settings for a project with one root it's not needed (maybe if you want a file you can share with others on the project), and if the reason you are changing settings per project is language related then it may make far more sense to add language settings to your main settings file and have them in effect every time you work on that kind of project.
In short every time you use Open Folder workbench.action.files.openFolder you are essentially switching to another workspace.
In the folder you want to add to your workspace, create a file {foldername}.code-workspace and in the file put in the following code.
{
"folders": [
{
"path": "."
}
]
}
Save and close the file. Back in Visual Studio Code, click menu File → Open Workspace... and select the .code-workspace file you created and it will open it as a new workspace without having to add a folder to an existing workspace.
In the File menu choose "Open Folder...". Select a folder. You can add folders to the workspace using "File" | "Add Folder to Workspace...".
Optionally, also go to "File" | "Preferences" | "Settings". The "User Settings" tab will be open by default. Look for the "Workspace Settings" tab and select it. Modify a setting, such as change the theme.
Then you can save the workspace using "Save" in the File menu.
When you close the workspace using "Close Workspace" in the File menu then if you changed the theme for the workspace then the theme should revert to the global theme. When you re-open the workspace VS Code will open the folder(s) that were added to the workspace and apply whatever settings that were specified for the workspace. There are a few settings that are ignored for workspaces for security reasons but all other settings can be overridden in workspaces.
It is possible to add multiple projects to a workspace; see Multi-root Workspaces.
If you already have a window open with project files or folders, and you want a new workspace to work on a different project:
From the 'File' menu, choose 'New Window'
From the 'File' menu, choose 'Add Folder to Workspace' and choose the root folder of your project
The new window is the workspace for your new project. You can save it to a named file with 'File', 'Save Workspace As...'
(The above instructions refer to Visual Studio Code 1.36.1 on macOS.)
Close all open files in VS Code.
Select File menu >> Open Folder... and open the folder containing your source files.
Select File Menu >> Save Workspace as... it should default to the folder you previously opened. If not browse to it and save the workspace file.
To create a new workspace in Visual Studio Code press F1 (or Crtl+Shift+P) and choose 'AL: GO!'

Multiple Launch Files in Visual Studio Code

Is there a way to debug multiple files from a single folder? I had expected that I could create multiple launch files in the .settings folder and pick the one I want to execute, but that did not seem to work. It seems to insist on only 'launch.json'.
VSCode supports only one launch.json, but you can have multiple launch configurations inside one launch.json. The example at https://code.visualstudio.com/Docs/debugging has 3 different launch configurations. You can specify any amount, and choose the active one using a drop down in the debug view.
Visual studio code allows to launch multiple configurations at once.
check out the Compound Launch Configurations in Visual Studio Code Website
NOTE: switch the Java Debug console from Integrated Terminal to Integrated Console so that all launch configurations will be displayed & will work correct acoordinglt to your expectations
Although the question is about multiple configurations for a single folder, just want to mention the alternative: multiple folders in a single workspace, each with their own launch.json.
One way is to just copy the .vscode/launch.json file to the other folder and edit it. The desired configuration can be picked up or edited from the drop-down to the right of the "Start Debugging" (Green "play") button.
use Multi-root workspaces
Multi-root workspaces are an advanced capability of VS Code that allows you to configure multiple distinct folders to be part of the workspace. Instead of opening a folder as workspace, you will open a .code-workspace JSON file that lists the folders of the workspace. For example:
{
"folders": [
{
"path": "my-folder-a"
},
{
"path": "my-folder-b"
}
]
}
https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspaces
so you can use multiple launch.json
Here are steps what I do to have 2 projects(A and B) and I can switch between them when I need to build or run
Create an empty Workspace
Add the Project A by choosing Add Folder to Workspace
Add tasks.json and launch.json to the project. Basically VS Code will help you to do that correctly. If there is something wrong, just delete .vscode folder and do again
Remove the folder of project A out of the Workspace
Do step 2,3 for Project B
Add project A again to the Workspace. Now, we will have 2 project A and B in the Workspace with their own .vscode
When you press Ctrl + Shift + B, VS Code will ask you which one you want to build
To debug or start without debug, you press Ctrl + Shift + D then on the left top selector, you select which project you want to run