Visual Studio Code Workspace [Complete Guide]

In this VS code tutorial, we will discuss what is a visual studio workspace. How to create a workspace in vs code? Also, we will see how to add a folder to a workspace in visual studio code and how to Open and Close a workspace.

What is visual studio code workspace?

  • A Visual Studio Code workspace can contain multiple files and folders. It allows customizing the settings and preferences of a workspace.
  • A VS Code workspace contains one or more root folders with a configurations file (.code-workspace)
  • .code-workspace is a JSON file that contains configuration information with the location of all root folders belonging to a workspace.

How to create a workspace in visual studio code

Now, let us see how to create a workspace in vs code.

Here, first I have created a few folders in my E drive. It looks like below:

Visual Studio Code Workspace
how to create a workspace in visual studio code

Now Open the Visual Studio code, then go to File -> Open Folder…

create a workspace in visual studio code
vs code workspace

Then select the Development folder like below:

How to create a workspace in visual studio code
create workspace vscode

Now click on File -> Save Workspace As…

create workspace vs code
creating workspace in visual studio code

Then you can provide a name for the workspace like below, click on Save.

how to create workspace vs code
vscode create workspace

Now, you can see in the VS code, the workspace will reflect like below:

vs code workspace
how to create a workspace in visual studio code

If you will open the physical file location, you can see the file got created.

create vs code workspace
how to create new workspace in visual studio code

You can open the code workspace file in a notepad also. You can see it contains the path of the folder and also the settings section.

This is just a JSON file.

open vs code workspace file
visual studio code create workspace

Anytime you can double click on the file to open the workspace in visual studio code.

open visual studio code workspace file
what is a workspace in vs code

This is how we can create a workspace in vs code.

How to add a folder to a workspace in visual studio code

Now, we will see how to add a folder to a workspace in code?

Open the workspace in vs code and then File -> Add folder to workspace…

add folder to a workspace in visual studio code
visual studio code workspace

Then you can select the folder which you want to add, and then your workspace will looks like below having both the folders.

create a new workspace in visual studio code
add folder to a workspace in vs code

This is how we can add a folder to a workspace in visual studio code.

How to Open and Close a Workspace in VS Code

Now we will see how to open and close a workspace in vs code.

You can directly open a workspace by double-clicking on the code-workspace file like below:

open visual studio code workspace
how to add workspace in visual studio

Or you can open vs code, go to File -> Open Workspace…

Then select the workspace file from the folder above and click on Open.

how to open visual studio code workspace
vscode open/close workspace

Similarly, to close a workspace from visual studio code, go to File -> Close workspace like below:

close workspace in visual studio code
vscode close workspace

You may like the following vs code tutorials:

In this visual studio code tutorial, we learned:

  • What is a visual studio code workspace?
  • How to create a workspace in visual studio code
  • How to add a folder to a workspace in visual studio code
  • How to Open and Close a Workspace in VS Code