VS Code中的“工作区”是什么?

辛龙野
2023-12-01

本文翻译自:What is a 'workspace' in VS Code?

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) new to VS Code. 如果不是很明显,我(非常)是VS Code的新手。

For example, VS Code talks about applying settings at the user level vs the workspace level . 例如,VS Code讨论了在用户级别与工作区级别应用设置

On the one hand, 一方面,

  • (a) it could refer to a project directory that you have opened; (a)它可以指你打开的项目目录; or 要么
  • (b) it could refer to everything you have opened in a particular window. (b)它可以指在特定窗口中打开的所有内容。

The page referenced above says 上面引用的页面说

"Workspace: These settings are stored inside your workspace in a .vscode folder and only apply when the workspace is opened."

#1楼

参考:https://stackoom.com/question/31GGw/VS-Code中的-工作区-是什么


#2楼

On some investigation, the answer appears to be (a). 在一些调查中,答案似乎是(a)。

When I go to change the settings, the settings file goes into a .vscode directory in my project directory. 当我去更改设置时,设置文件进入我的项目目录中的.vscode目录。


#3楼

You can save settings at the workspace level and you can open multiple folders in a workspace. 您可以在工作区级别保存设置,并可以在工作区中打开多个文件夹。 If you want to do either of those things, use a workspace, otherwise, just open a folder. 如果要执行上述任一操作,请使用工作区,否则只需打开文件夹即可。

A VS Code workspace is a list of a project's folders and files. VS Code工作空间是项目文件夹和文件的列表。 A workspace can contain multiple folders. 工作区可以包含多个文件夹。 You can customize the settings and preferences of a workspace. 您可以自定义工作区的设置和首选项。


#4楼

A workspace is just a text file with a (.code-workspace) extension. 工作空间只是一个带有(.code-workspace)扩展名的文本文件。 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 VS Code. 我也对工作空间的概念以及如何在VS Code中实现它感到沮丧。 I found a method that suits me. 我发现了一种适合我的方法。

Start with a single "project" folder. 从单个“项目”文件夹开始。

Open VSCode and close any open workspaces or files or folders. 打开VSCode并关闭所有打开的工作区或文件或文件夹。 You should see only "OPEN EDITORS" and "NO FOLDER OPENED" in the EXPLORER. 您应该只在EXPLORER中看到“OPEN EDITORS”和“NO FOLDER OPENED”。
From the Menu Bar --> File --> Open Folder... . 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 ". 将其命名为您想要的任何名称,然后单击“ Select Folder ”。 It will appear in the VS Code EXPLORER . 它将出现在VS Code EXPLORER

Now from the Menu Bar --> File --> Save Workspace As... . 现在从Menu Bar --> File --> Save Workspace As... Name the workspace and save it wherever you want to keep all your workspace's, (not necessarily where your project folders are). 命名工作区并将其保存在您想要保留所有工作区的位置(不一定是项目文件夹所在的位置)。 I put all mine in a folder called "VS Code workspace". 我把我的全部放在一个名为“VS 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. 它将保存为( .code-workspace )文件,并且只是它包含(或指向)所有文件和文件夹的索引,无论它们位于硬盘驱动器上的哪个位置。 You can look at it by opening it with a text editor. 您可以通过使用文本编辑器打开它来查看它。 Close the folder you created and close VS Code. 关闭您创建的文件夹并关闭VS Code。

Now find your workspace "file" and double click on it. 现在找到您的工作区“文件”并双击它。 This will open VS Code with the folder you created in your workspace. 这将使用您在工作区中创建的文件夹打开VS Code。 Or you can open VS Code and use "Open Workspace". 或者您可以打开VS Code并使用“Open Workspace”。

Any folders you create from within your VS Code workspace will be inside your first folder. 您在VS Code工作区中创建的任何文件夹都将位于第一个文件夹中。 If you want to add any more top level folders, create them first wherever you want them and then use " Add To Workspace.. " from VS Code. 如果要添加任何更多顶级文件夹,请先在任意位置创建它们,然后使用VS Code中的“ Add To Workspace.. ”。


#5楼

The main utility of a workspace (and maybe the only one) is to allow to add multiple independent folders that compounds a project. 工作空间(也许是唯一的)的主要功能是允许添加多个独立的文件夹来组合项目。 For example: 例如:

- WorkspaceProjectX  
-- ApiFolder   (maybe /usr/share/www/api)  
-- DocsFolder  (maybe /home/user/projx/html/docs)  
-- WebFolder   (maybe /usr/share/www/web)

So you can group those in a work space for a specific project instead of have to open multiple folders windows. 因此,您可以将工作空间中的那些分组为特定项目,而不必打开多个文件夹窗口。

You can learn more here . 你可以在这里了解更多。


#6楼

As of May 2018, it seems that workspace in VS Code allows you to have quick access to different but related projects. 截至2018年5月,似乎VS Code中的工作区允许您快速访问不同但相关的项目。 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 参考1
reference 2 参考2

 类似资料: