I can\'t quite believe I am asking this question, but I have not been able to find a definition in the documentation. In case it isn\'t painfully obvious, I am (very) ne
So, yet again the lesson of not polluting the source tree of a project with artifacts that aren't directly related to that project is being ignored.
There is zero reason for a Visual Studio Code workspace file (workspaces.json) or directory (.vscode) or whatever to be placed in the source tree. It could just as easily have been placed under your user settings.
I thought we figured this out about 20+ years ago, but it seems that some lessons are doomed to be repeated.
As of May 2018, it seems that a workspace in Visual Studio Code allows you to have quick access to different but related projects. All without having to open a different folder.
And you can have multiple workspaces too. See references here and you will get the full picture of it:
Reference 1
Reference 2
A project that consists of one or more root folders, along with all of the Visual Studio Code configurations that belong to that project. These configurations include:
Visual Studio Code does not use the term consistently across the UI (I've opened a GitHub issue to address this). Sometimes it refers to a workspace as described above, and other times it refers to a workspace as a project that is specifically associated with a .code-workspace
file.
A good example being the recent files widget. Notice in the linked screenshot that all projects are grouped under the same "workspaces" heading, which would indicate that everything there is a workspace. But then projects with a .code-workspace
file are given a "Workspace" suffix, contradicting the heading and indicating that only those files are actually workspaces.
.code-workspace
file?A JSON with Comments file that stores all of the configuration data mentioned above, in addition to the location of all root folders belonging to a workspace.
.code-workspace
file?Only if you're creating a multi-root workspace, in which case you'll have a single .code-workspace
file that automatically restores all of the workspace settings, in addition to all of the root folders that you want to be displayed in the Explorer.
Everything is automated.
When you open a folder in Visual Studio Code and start making modifications to the editor that are specifically related to the project you're currently working on, Visual Studio Code automatically creates a .vscode
folder and stores it in the root of the project folder that you're working on. This .vscode
folder has files that store the changes you made.
For example, if you change Visual Studio Code settings that you want to apply only to your current project, Visual Studio Code creates a settings.json
file with those updates, and that file is stored in the .vscode
folder.
You can create a .code-workspace
file that includes just a single root folder if you really want to. You'd then be able to either open the project folder directly, or open the workspace file. But I can't think of any reason why this would be beneficial.
.code-workspace
file?Go to menu File → Save Workspace As...
Go to menu File → Add Folder to Workspace....
.code-workspace
file?Go to menu File → Open Workspace....
Alternatively, double click the .code-workspace
file. Visual Studio Code won't open the actual file. Instead, it will read that file and open the folders that belong to that workspace.
.code-workspace
file?Go to menu File → Open... and select the target .code-workspace
file.
Alternatively, open the workspace associated with that file. Then open the command palette, search for, and select the Workspaces: Open Workspace Configuration File command.
If the Visual Studio Code is a fresh installation;
Click on extensions, Search for "python" and click on install
Click on view -> explorer If there in no folder added a folder to the Workspace (File->Add folder to Workspace)
If you want to use a virtual python environment, Click on File -> Preference -> settings
Click on "{} open settings JSON" which is in top right corner of the window, then add the path to python.exe file which is in the virtual environment
{
"python.pythonPath": "C:\\PathTo\\VirtualENV\\python.exe"
}
A workspace is just a text file with a (.code-workspace) extension. You can look at it by opening it with a text editor. I too was frustrated by the idea of a workspace and how it is implemented in Visual Studio Code. I found a method that suits me.
Start with a single "project" folder.
Open Visual Studio Code and close any open workspaces or files or folders. You should see only "OPEN EDITORS" and "NO FOLDER OPENED" in the EXPLORER.
From the menu bar* → File → Open Folder.... Navigate to where you want to put your folder and right click to open a new folder. Name it whatever you want, then click on "Select Folder". It will appear in the *Visual Studio Code explorer.
Now from menu File → Save Workspace As.... Name the workspace and save it wherever you want to keep all your workspaces, (not necessarily where your project folders are). I put all mine in a folder called "Visual Studio Code workspace".
It will be saved as a (.code-workspace
) file and is just an index to all the files and folders it contains (or points to) wherever they may be on your hard drive. You can look at it by opening it with a text editor. Close the folder you created and close Visual Studio Code.
Now find your workspace "file" and double click on it. This will open Visual Studio Code with the folder you created in your workspace. Or you can open Visual Studio Code and use "Open Workspace".
Any folders you create from within your Visual Studio Code workspace will be inside your first folder. If you want to add any more top level folders, create them first wherever you want them and then use "Add To Workspace.." from Visual Studio Code.
Do you ever have to built a new directory and open a new Visual Studio Code window for a test project or for a feature that you want to add to your main project? Ok, so you need a workspace and enough CPU high usage...
I just wanted to mention a common usage of workspaces in Visual Studio Code in addition to all other answers.