Multi-root Workspaces in Visual Studio Code (2024)

You can work with multiple project folders in Visual Studio Code with multi-root workspaces. This can be helpful when you are working on several related projects at one time. For example, you might have a repository with a product's documentation that you like to keep current when you update the product source code.

Multi-root Workspaces in Visual Studio Code (1)

Note: If you'd like to learn more about the VS Code "workspace" concept, you can review What is a VS Code "workspace"? Unless you are explicitly creating a multi-root workspace, a "workspace" is just your project's single root folder.

Adding folders

It is easy to add another folder to your existing workspace. There are several gestures for adding folders:

Add Folder to Workspace

The File > Add Folder to Workspace command brings up an Open Folder dialog to select the new folder.

Multi-root Workspaces in Visual Studio Code (2)

Once a root folder is added, the Explorer will show the new folder as a root in the File Explorer. You can right-click on any of the root folders and use the context menu to add or remove folders.

Multi-root Workspaces in Visual Studio Code (3)

The File Explorer should work and behave as before. You can move files between root folders and use any of the typical file operation actions provided in the context menu and the Explorer view.

Settings like files.exclude are supported for each root folder if configured, and across all folders if configured as global user setting.

Drag and drop

You can use drag and drop to add folders to a workspace. Drag a folder to the File Explorer to add it to the current workspace. You can even select and drag multiple folders.

Note: Dropping a single folder into the editor region of VS Code will still open the folder in single folder mode. If you drag and drop multiple folders into the editor region, a new multi-root workspace will be created.

You can also use drag and drop to reorder folders in the workspace.

Multiple selection native file open dialogs

Opening multiple folders with your platform's native file open dialog will create a multi-root workspace.

command line --add

Add a folder or multiple folders to the last active VS Code instance for a multi-root workspace.

 code --add vscode vscode-docs

Removing folders

You can remove a folder from a Workspace with the Remove Folder from Workspace context menu command.

Workspace file

When you add multiple folders, they are initially placed in a Workspace titled UNTITLED WORKSPACE and that name will remain until you save the workspace. You do not need to save a Workspace until you want to have it in a permanent location, for example, on your Desktop. Untitled Workspaces are present as long as the VS Code instance they are using is open. Once you completely close an instance with an untitled workspace, you will be asked to save it if you plan to open it again in the future:

Multi-root Workspaces in Visual Studio Code (4)

When you save your workspace, it will create a .code-workspace file and the file name will be displayed in the File Explorer.

Save Workspace As...

If you want to move your Workspace file to a new location, you can use the File > Save Workspace As command, which will automatically set the correct folder paths relative to the new Workspace file location.

Opening workspace files

To reopen a Workspace, you can:

  • Double-click the .code-workspace file in your platform's Explorer.
  • Use the File > Open Workspace command and select the Workspace file.
  • Select the Workspace from the File > Open Recent (⌃R (Windows, Linux Ctrl+R)) list.
    • Workspaces have a (Workspace) suffix to differentiate them from folders.

Multi-root Workspaces in Visual Studio Code (5)

Just like Close Folder when a single folder is open in VS Code, there is a Close Workspace (⌘K F (Windows, Linux Ctrl+K F)) command to close the active Workspace.

Workspace file schema

The schema of .code-workspace is fairly straightforward. You have an array of folders with either absolute or relative paths. Relative paths are better when you want to share Workspace files.

You can override the display name of your folders with the name attribute, to give more meaningful names to folders in the Explorer. For example, you could name your project folders such as 'Product' and 'Documentation' to easily identify the content by folder name:

{ "folders": [ { // Source code "name": "Product", "path": "vscode" }, { // Docs and release notes "name": "Documentation", "path": "vscode-docs" }, { // Yeoman extension generator "name": "Extension generator", "path": "vscode-generator-code" } ]}

which will result in the following Explorer display:

Multi-root Workspaces in Visual Studio Code (6)

As you can see from the example above, you can add comments to your Workspace files.

The Workspace file can also contain Workspace global settings under settings and extension recommendations under extensions, which we will discuss below.

Multi-root Workspaces in Visual Studio Code (7)

General UI

Editor

There are only a few changes to the VS Code UI when you are using multi-root workspaces, primarily to disambiguate files between folders. For example, if there is a name collision between files in multiple folders, VS Code will include the folder name in tabbed headers.

Multi-root Workspaces in Visual Studio Code (8)

If you'd always like to see the folder displayed in the tabbed header, you can use the workbench.editor.labelFormat setting "medium" or "long" values to show the folder or full paths.

"workbench.editor.labelFormat": "medium"

VS Code UI such as the OPEN EDITORS and Quick Open (⌘P (Windows, Linux Ctrl+P)) lists include the folder name.

Multi-root Workspaces in Visual Studio Code (9)

If you are using an File Icon Theme and the active theme supports it, you will see a special Workspace icon.

Below you can see the Workspace icons from the built-in Minimal (Visual Studio Code) file icon theme:

Multi-root Workspaces in Visual Studio Code (10)

Search

VS Code features like global search work across all folders and group the search results by folder.

Multi-root Workspaces in Visual Studio Code (11)

When you have a multi-root workspace open, you can choose to search in a single root folder by using the ./ syntax in the files to include box. For example, if you enter ./project1/**/*.txt, that will search for all .txt files under the project1/ root folder.

Settings

With multiple root folders in one workspace, it is possible to have a .vscode folder in each root folder defining the settings that should apply for that folder. To avoid setting collisions, only resource (file, folder) settings are applied when using a multi-root workspace. Settings that affect the entire editor (for example, UI layout) are ignored. For example, two projects cannot both set the zoom level.

User settings are supported as with single folder projects and you can also set global Workspace settings that will apply to all folders in your multi-root Workspace. Global Workspace settings will be stored in your .code-workspace file.

{ "folders": [ { "path": "vscode" }, { "path": "vscode-docs" }, { "path": "vscode-generator-code" } ], "settings": { "window.zoomLevel": 1, "files.autoSave": "afterDelay" }}

When you go from a single folder instance to multiple folders, VS Code will add the appropriate editor-wide settings from the first folder to the new global Workspace settings.

You can easily review and modify the different settings files through the Settings editor. The Settings editor tabs let you select your User settings, global Workspace settings, and individual folder settings.

Multi-root Workspaces in Visual Studio Code (12)

You can also open specific settings files with the commands:

  • Preferences: Open User Settings - Open your global User settings
  • Preferences: Open Workspace Settings - Open the settings section of your Workspace file.
  • Preferences: Open Folder Settings - Open the settings for the active folder.

Global Workspace settings override User settings and folder settings can override Workspace or User settings.

Unsupported folder settings

Unsupported editor-wide folder settings will be shown as grayed out in your folder settings and are filtered out of the DEFAULT FOLDER SETTINGS list. You will also see an information icon in front of the setting.

Multi-root Workspaces in Visual Studio Code (13)

Debugging

With multi-root workspaces, VS Code searches across all folders for launch.json debug configuration files and displays them with the folder name as a suffix. Additionally VS Code will also display launch configurations defined in the workspace configuration file.

Multi-root Workspaces in Visual Studio Code (14)

The example above shows the debugging configurations for the TSLint extension. There is a launch configuration from the tslint extension folder to start the extension running in the VS Code Extension Host and also an attach configuration from the tslint-server folder to attach the debugger to a running TSLint server.

You can also see the three Add Config commands for the folders, tslint, tslint-server, and tslint-tests, in the vscode-tslint Workspace. The Add Config command will either open an existing launch.json file in the folder's .vscode subfolder or create a new one and display the debugging configuration template dropdown.

Multi-root Workspaces in Visual Studio Code (15)

Variables used in a configuration (for example ${workspaceFolder} or the now deprecated ${workspaceRoot}) are resolved relative to the folder they belong to. It is possible to scope a variable per workspace folder by appending the root folder's name to a variable (separated by a colon).

Workspace launch configurations

Workspace scoped launch configurations live in the "launch" section of the workspace configuration file (Workspaces: Open Workspace Configuration File in the Command Palette):

Multi-root Workspaces in Visual Studio Code (16)

Alternatively, new launch configurations can be added via the "Add Config (workspace)" entry of the Launch Configuration dropdown menu:

Multi-root Workspaces in Visual Studio Code (17)

A compound launch configuration can reference the individual launch configurations by name as long as the names are unique within the workspace, for example:

 "compounds": [{ "name": "Launch Server & Client", "configurations": [ "Launch Server", "Launch Client" ] }]

If the individual launch configuration names are not unique, the qualifying folder can be specified with a more verbose "folder" syntax:

 "compounds": [{ "name": "Launch Server & Client", "configurations": [ "Launch Server", { "folder": "Web Client", "name": "Launch Client" }, { "folder": "Desktop Client", "name": "Launch Client" } ] }]

In addition to compounds, the launch section of the workspace configuration file can contain regular launch configurations too. Make sure that all used variables are explicitly scoped to a specific folder because otherwise they are not valid for the workspace. You can find more details about explicitly scoped variables in the Variables Reference.

Here is an example for a launch configuration where the program lives in a folder "Program" and where all files from a folder "Library" should be skipped when stepping:

"launch": { "configurations": [{ "type": "node", "request": "launch", "name": "Launch test", "program": "${workspaceFolder:Program}/test.js", "skipFiles": [ "${workspaceFolder:Library}/out/**/*.js" ] }]}

Tasks

Similar to how VS Code searches for debugging configurations, VS Code will also try to autodetect tasks from gulp, grunt, npm, and TypeScript project files across all folders in a workspace as well as search for tasks defined in tasks.json files. The location of tasks is indicated by a folder name suffix. Note that tasks defined in tasks.json must be version 2.0.0.

Multi-root Workspaces in Visual Studio Code (18)

From the TSLint extension Workspace example above, you can see that there are two configured tasks from tasks.json files in the tslint and tslint-tests folders and numerous autodetected npm and TypeScript compiler detected tasks.

Workspace task configuration

Workspace scoped tasks live in the "tasks" section of the workspace configuration file (Workspaces: Open Workspace Configuration File in the Command Palette). Only "shell" and "process" type tasks can be defined in the workspace configuration file.

Source Control

With multi-root workspaces, there is a SOURCE CONTROL PROVIDERS section that gives you an overview when you have multiple active repositories. These can be contributed by several SCM providers; for example, you can have Git repositories side-by-side with Azure DevOps Server workspaces. As you select repositories in this view, you can see the source control details below.

Multi-root Workspaces in Visual Studio Code (19)

You can use Ctrl+Click or Shift+Click to select multiple repositories. Their details will appear as separate regions underneath.

Extensions

If you are an extension author, you can review our Adopting Multi Root Workspace APIs guide to learn about VS Code multi-root workspace APIs and how to make your extension work well across multiple folders.

Below are some of the popular extensions that have adopted the multi-root workspace APIs.

Note: If an extension doesn't yet support multiple folders, it will still work in the first folder of your multi-root workspace.

Extension recommendations

VS Code supports folder level extension recommendations through the extensions.json files under the folder's .vscode subfolder. You can also provide global Workspace extension recommendations by adding them to your .code-workspace file. You can use the Extensions: Configure Recommended Extensions (Workspace Folder) command to open your Workspace file and add extension identifiers ({publisherName}.{extensionName}) to the extensions.recommendations array.

{ "folders": [ { "path": "vscode" }, { "path": "vscode-docs" } ], "extensions": { "recommendations": ["eg2.tslint", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] }}

Next steps

  • What is a VS Code "workspace"? - More about single-folder and multi-root workspaces.
  • Debugging - Learn how to set up debugging for your application.
  • Tasks - Tasks let you run external tools like compilers within VS Code.

Common questions

How can I go back to working with a single project folder?

You can either close the Workspace and open the folder directly or remove the folder from Workspace.

As an extension author what do I need to do?

See our Adopting Multi Root Workspace APIs guide. Most extensions can easily support multi-root workspaces.

04/04/2024

Multi-root Workspaces in Visual Studio Code (2024)

FAQs

Can I have multiple workspaces in VS Code? ›

You can work with multiple project folders in Visual Studio Code with multi-root workspaces. This can be helpful when you are working on several related projects at one time. For example, you might have a repository with a product's documentation that you like to keep current when you update the product source code.

What is the root of the workspace in VS Code? ›

Note: A VS Code "workspace" is usually just your project root folder. Workspace settings as well as debugging and task configurations are stored at the root in a .vscode folder. You can also have more than one root folder in a VS Code workspace through a feature called Multi-root workspaces.

Why use workspaces VS Code? ›

The most obvious advantage is that a multi-root workspace allows you to work with multiple projects that may not be stored inside the same parent folder on disk. You can pick folders from anywhere to add to the workspace.

How do I trust all workspaces in VS Code? ›

Trusting a workspace
  1. Workspaces: Manage Workspace Trust command from the Command Palette (Ctrl+Shift+P)
  2. Manage Workspace Trust from the Manage gear in the Activity bar.

Can I have multiple workspaces? ›

By default, you can create only one WorkSpace per user per directory. However, if needed, you can create more than one WorkSpace for a user, depending on your directory setup. If you have only one directory for your WorkSpaces, create multiple usernames for the user.

Can you have two projects open in VS Code? ›

You can have multiple projects within a single workspace on Visual Studio Code by using the "Multi-root Workspaces" feature. This feature allows you to open multiple folders in a single instance of Visual Studio Code, and treat them as a single workspace.

What is workspace root? ›

You can have multiple workspaces on your computer. All files within a Helix Server client workspace share a root directory, called the client workspace root. The workspace root is the highest-level directory of the workspace under which the managed source files reside.

How do I switch workspaces in VS Code? ›

vscode-workspace-switcher
  1. Use the W -shaped icon in the Activity Bar and then click on the O -shaped icon next to the name of the workspace you want to open,
  2. or, use the extension's subection in Explorer, in the same way,
  3. or, Use the Ctrl-k Ctrl-w chord.
Aug 20, 2020

What is the difference between VS Code profiles and workspaces? ›

For a beginner, the most important difference between workspaces and profiles is that workspaces are specific to a project, while profiles are specific to a user. This means that if you have multiple projects that use different extensions or keyboard shortcuts, you can create a separate profile for each project.

What is the benefit of setting up workspaces? ›

Collaborative workspaces bring people together in a shared environment. In doing so, they consolidate the amount of physical space needed to individually accommodate employees. In turn, it reduces cost, maximizes available workspace, and encourages better use of floor space.

What is the purpose of workspaces? ›

A workspace offers a single platform where organizations can communicate, manage, and complete tasks, without struggling with different integrations.

How do I remove all workspaces in VS Code? ›

right click in the workspace you'd like to remove and select the "Remove Folder from Workspace" item; the name of the workspace will become: "NO FOLDER OPENED" that is the one you'll get when you installed the very first time Visual Studio Code.

How do you exclude from workspace VS Code? ›

To use VS Code's file exclusions, go to VS Code Settings > Workspace, search File: Exclude and select Add Pattern. The Workspace setting has information about how VS Code uses wildcard patterns to manage exclusions in the editor.

Is the Visual Studio Code legit? ›

VS Code General Review

- It's free, developed and maintained by a tech giant: Microsoft. - It's so easy to use, as well as it is easy to install extensions to have more functionalities. - I'm in love with the extension: Code share which enables me to share and live-edit my code with other team members.

How to work with multiple projects in Visual Studio Code? ›

The first step is to open Visual Studio Code, and With your mouse, click and drag Project folder, then drop it on your VS Code workspace. With your mouse, click and drag Second folder, then drop it on Explorer space. Click Add Folder to Workspace. To save the Workspace, Click File tab.

How do you type in multiple places at once in VS Code? ›

Multiple Cursors & Selections
  1. Place multiple cursors: Option–Click (Mac) or Alt–Click (Windows)
  2. Multiple selections (discontinuous): Hold Option (Mac) or Alt (Windows) while dragging.
  3. To make a single discontinuous selection area across multiple lines: Hold Option–Shift (Mac) or Alt–Shift (Windows) while dragging.

How do I have two instances of VS Code? ›

  1. Press "Ctrl + Shift + P"
  2. Move the cursor to the line "Workspaces: Duplicate As Workspace in New Window".
  3. Click the setting icon on the line to configure the keybinding.
  4. Assign "Ctrl + Alt + D" (or other keys as you like) to this command.
  5. Use "Ctrl + Alt + D" to open multiple instances.
Apr 30, 2015

What is multiple workspaces? ›

Workspaces refer to the grouping of windows on your desktop. You can create multiple workspaces, which act like virtual desktops. Workspaces are meant to reduce clutter and make the desktop easier to navigate.

Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 6031

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.