What is the Difference between folder and workspace? - visual-studio-code

"There are two options in vscode namely "Open Folder" and "Open WorkSpace". What is the difference between them? When should we use folder or workspace?

vscode --> WorkSpace
In workspace we have privilege to save our setting at the workspace level, not only this here 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.
In vscode there is list of project's folders and files.A workspace can contain multiple folders. You can customize the settings and preferences of a workspace.
A workspace is a folder, or multiple folders, mapped to areas in TFS. When code is checked out of TFS, the code is stored locally based off your workspace mappings. When you make changes to your code files, you are making those changes locally, to the files contained in your workspace.
One of the main reasons for workspaces is isolation. It provides a private sandbox where code changes can be made without having to worry if the changes will affect other team members. The changes remain in the local workspace until are checked into TFS.
TFS was designed to allow for one or more workspaces on the same machine. A single workspace can be created that contains multiple team projects and their code, or a more targeted workspace that only contains a particular project. There is no hard and fast rule for the best way to create workspaces. It will depend on personal preference, methodology, environment and the like.
Reference
vscode --> folder
When we want to work on single folder irrespective of their dependencies or in-dependencies and when we wants to opens a new instance of VS Code scoped to the selected folder OR to the folder containing the selected file.
Reference

The VSCode 1.53 (Jan. 2021) mentions the new article "What is a VS Code "workspace"?"
What is a VS Code "workspace"?
A Visual Studio Code "workspace" is the collection of one or more folders that are opened in a VS Code window (instance).
In most cases, you will have a single folder opened as the workspace but, depending on your development workflow, you can include more than one folder, using an advanced configuration called Multi-root workspaces.
The concept of a workspace enables VS Code to:
Configure settings that only apply to a specific folder or folders but not others.
Persist task and debugger launch configurations that are only valid in the context of that workspace.
Store and restore UI state associated with that workspace (for example, the files that are opened).
Selectively enable or disable extensions only for that workspace.
You may see the terms "folder" and "workspace" used interchangeably in VS Code documentation, issues, and community discussions.
Think of a workspace as the root of a project that has extra VS Code knowledge and capabilities.
Note: It is also possible to open VS Code without a workspace. For example, when you open a new VS Code window by selecting a file from your platform's File menu, you will not be inside a workspace. In this mode, some of VS Code's capabilities are reduced but you can still open text files and edit them
The same article adds:
What is the benefit of multi-root workspace over a folder?#
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.
Even if you are mainly working in a single-folder-based project, you can benefit from using .code-workspace files.
You can store multiple .code-workspace files inside the folder to provide a scoped folder-view of certain aspects of the project depending on the scenario (for example client.code-workspace, server.code-workspace to filter out unrelated folders from the File Explorer).
Since .code-workspace files support relative paths for the folders section, these workspace files will work for everyone independent of where the folder is stored.
Finally, if for some projects you want to apply the same set of workspace settings or tasks/launch configurations, consider adding these into a .code-workspace file and add/remove these folders from that workspace.

Related

VS Code - Multi-root workspace not showing all git repositories in source control panel

I have a multi-root workspace set up where all of the folders in my workspace are git repositories.
However, for some reason only some of them show up in the Source Control panel, even though I've added them all to the workspace in the same way (File > Add Folder to Workspace).
How do I get all of the repositories to show up in the Source Control panel?
This is what my workspace looks like:
This is what my source control looks like:
For me, this issue ended up being a folder permissions issue. I ran VS Code as administrator and the missing directories showed up. I looked at the directory owners and noticed the working directories were own by my user, and the non working directories were owned by the admin group (which my user belonged to). Changing the directory ownership to my main user was the long term fix.
two out rabbit hole. Meh.

Have a folder with dynamic content automatically controlled by TFS

I have a web project that has a folder with dynamic generated content with 4000+ files, and those files must be on source control.
I would like these files to be automatically included in the project so I can upload them to source control instead of me having to track them down and add them to project.
An option would be to exclude all and them re-include them before a check in but it takes too much time in Visual Studio.
Another question, can I solve it if I use GIT instead of TFS source control?
Using GIT, when you open a version controlled project, you'll see the new added files will appear in "Untracked Files" in "Changes" tab, after selecting "Add All", the new added files will be added and ready for Commit. Check: http://incyclesoftware.com/2013/08/version-control-with-tfs-2013-git-repository/
Using TFVC, you can add new files from VS, or TFS Power Tool, or use tf.exe command line. Check http://www.asp.net/web-forms/overview/deployment/configuring-team-foundation-server-for-web-deployment/adding-content-to-source-control and http://nullablecode.com/2013/01/tfs-windows-shell-tfs-power-tools/

Should I commit the .vscode folder to source control?

Is the .vscode folder meant to be committed to source control?
In a fresh project, the folder is empty, except the settings.json file. What kind of things would go into this folder? Is it machine-specific, developer-specific like the .vs folder and thus not be committed? Or should all developers share this folder and thus it should be committed?
The comment at the top of the file .vscode/settings.json states:
// Place your settings in this file to overwrite default and user settings.
{
}
This seems to imply that the folder should contain project-specific settings and thus be included in source. Also, this post on UserVoice seems to imply some typings would go in there, also suggesting that it should be committed.
Check in the .vscode folder if you want to share settings, task configuration and debug configuration with the team. I think generally it makes sense to share settings (e.g. whitespace vs tabs) with the team if you want to enforce settings in a team. We in the VS Code team share debug and task specific settings as well because we want our team to have the same set of debug targets and task targets for VS Code.
Btw you do not need to have a .vscode folder in your project for settings. You can also configure settings on a user level.
Commit some files in .vscode folder
Recommendation is to generally exclude .vscode folder, but leave select JSON files that allow other developers to recreate shared settings.
Examples of settings to include:
Language specific test configurations to run the test suite(s) (settings.json)
Extension settings for linters and code formatting tools to enforce the language rules used in this repo (settings.json)
Run and debug configurations (launch.json)
Shared tasks - if managed with VS Code (tasks.json)
Note that some settings can be stored in the user settings or workspace file, or transferred to it from the .vscode folder. See below.
Sample .gitignore code
Here are the settings, as suggested at https://gitignore.io. You can search for "VisualStudioCode" there to get the latest recommended .gitignore file. I use this website as a starting point for .gitignore for most of my new repos:
# Created by https://www.gitignore.io/api/visualstudiocode
# Edit at https://www.gitignore.io/?templates=visualstudiocode
### VisualStudioCode ###
.vscode/* # Maybe .vscode/**/* instead - see comments
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
**/.history
# End of https://www.gitignore.io/api/visualstudiocode
In the above .gitignore file, the .vscode/* line (note: some debate on whether the * should be included - see comments; .vscode/**/* may be better to ignore nested folders as well) says to exclude everything in the .vscode folder, but then the !.vscode/a_specific_file lines tell git to "not" ignore some specific files in that folder (settings.json, launch.json, etc.). The end result is that everything is excluded in the .vscode folder except for the files specifically named in one of those other lines.
Other Factors
Including the .vscode folder in your repo doesn't actually hurt anyone that uses a different IDE (or text/code editor).
However, it may cause issues for other people using VS Code, or some of the settings may not load properly, if these files include generic settings that require something specific to your environment - like the absolute path the repo is installed in. The key is to avoid saving settings that are custom to your local environment, only sharing those that can (or, in the case of this repo, should) be used by everyone.
For example, if IDE setting files have absolute paths to the repo or any files/libraries, etc., then that is bad, don't share. But if all the references are relative, then they should work for anyone using the repo (although, be careful about path specification differences between Windows/Unix..).
About User, Workspace, and Folder settings
Note: the settings files in the .vscode folder are generally updated when you make changes to the folder version of the settings - but this appears to depend on how individual extensions are coded, because I've run across multiple exceptions to this rule.
If you make changes to the user settings, they are usually stored elsewhere (location depends on OS settings, usually in a home directory).
If you make changes to the workspace settings, they are usually stored in the *.code-workspace file that you are currently using. If you don't have a workspace (you directly opened a folder instead), then they will likely go to the .vscode folder, but, overall, this may depend on the extension that owns the setting anyway.
So, you should generally put custom settings for your personal PC into the user settings, and put generic settings into the workspace or folder settings.
Between commit/ignore there is third clever option: commit with .default suffix.
For example you can add settings.json to .gitignore, and commit settings.json.default, much like it is common practice (in my team) with .env files.
I took this advice from video Commit editor settings to version control? by Mattias Petter Johansson
never commit .vscode/settings.json - with the weird exception of search.exclude . If you really need to, be very careful of putting only settings particular of your project that you want to enforce to other developers.
for validation, formatting, compilation use other files like package.json, .eslint, tsconfig.json, etc
The only .vscode that makes sense to include are complex launch configs for debugging.
Be careful, there could be a third party extension in your system that could put private information there !
What you can't do is copy & paste the whole settings.json contents file to .vscode/settings.json. I'm seeing some people doing this and committing the file is an atrocity. In that case you will not only break others workspace but worst, you will be enforcing settings to users that you shouldn't like aesthetics, UI, experience. You probably will break their environments because some are very system dependent. Imagine I have vision problems so my editor.* user settings are personalize and when I open your project the visuals change. Imagine I have vision problems s I need to personalize user editor.* settings to be able to work. I would be angry.
If you are serious don't commit .vscode/settings.json. In general, settings that could be useful for a particular project like validation, compilation, makes sense but in general you can use particular tools configuration files like .eslint, tsconfig.json, .gitignore, package.json. etc. I guess vscode authors just added the file for simplifying newcomer experience but if you want to be serious don't!
The only exception, and in very particular cases could be search.exclude
Why not just looking at the practice, other than the arguments around here?
One of the biggest project that keeps .vscode I found so far is Mozilla Firefox.
It looks like the Firefox team shares their common tasks and recommended extensions.
So I guess it is not a bad idea to keep .vscode, as long as you know what you are doing.
I will update this post when I see other big projects that shares .vscode.
Same as other answers: no.
As an illustration, consider the approach chosen by Git 2.19 (Q3 2018), which adds a script (in contrib/) to help users of VSCode work better with the Git codebase.
In other words, generate the .vscode content (if it does not yet exist), don't version it.
See commit 12861e2, commit 2a2cdd0, commit 5482f41, commit f2a3b68, commit 0f47f78, commit b4d991d, commit 58930fd, commit dee3382, commit 54c06c6 (30 Jul 2018) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit 30cf191, 15 Aug 2018)
contrib: add a script to initialize VS Code configuration
VS Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux.
Among other languages, it has support for C/C++ via an extension, which offers to not only build and debug the code, but also Intellisense, i.e. code-aware completion and similar niceties.
This patch adds a script that helps set up the environment to work effectively with VS Code: simply run the Unix shell script contrib/vscode/init.sh, which creates the relevant files, and open the top level folder of Git's source code in VS Code.
Okay, this may seem pretty late, but if you're finding it difficult to ignore .vscode/ without including any sub-file, you could just ignore the directory:
.vscode/
and then manually track the file you want:
git add -f .vscode/launch.json
The -f adds files even when they're ignored. Once Git sees changes to .vscode/launch.json you'll be prompted to commit them just like any other file.
this actually worked for me, caused i experience the same issue, trying to ignore the .vscode/ path, without including a sub-file settings.json
A simple way to keep your settings without commit it in your project git repository is creating a workspace and add folder into it.
When do you create a workspace, you need to save a file code-workspace. This file contains custom settings, just save this file out of the git repository and will be free to add .vscode into .gitignore file.
The answer is "NO",because .vscode folder is for this editor and you should't push these personal settings to repo in case of confusing others ,so you can add it to your project's .gitignore file to ignore the changes

Eclipse .metadata folder out of workspace

The .metadata directory is in the directory of my workspace. Can I configure Eclipse so that the .metadata directory is not within the workspace?.
The reason is that we are many developers who use the same project directory and, if everyone starts its Eclipse instance on the same workspace, .metadata is modified by each developer.
As far as I know, there is no way to have the .metadata directory outside of the workspace directory. However, you can have your actual projects outside of your workspace directory!
For each developer, create a separate workspace, e.g. on that person's local hard drive. This workspace will hold that user's .metadata directory as well as references to the actual projects.
Import the projects from the "shared workspace" (which now no longer is an Eclipse workspace but an ordinary shared directory) into the individual workspaces using Import -> Existing Projects into Workspace. Uncheck the Copy Projects into Workspace checkbox!
This way, each developer has his own workspace, with individual settings etc., while the projects still reside in a shared directory. However, this can lead to serious troubles, as Eclipse will be unaware of other people editing files in the projects. Thus, this should only be used as a workaround in case 'proper' version control systems like SVN or Git are not an option.
You cannot configure the path of the .metadata directory.
The way you are trying to use Eclipse is only going to lead to grief for you and your team. Each workspace keeps track of whether it has seen the current revision of the file. If multiple people are editing the same project files, everyone on the team will have to constantly invoke refresh. There is also risk of loosing changes as one team member can easily and silently overwrite changes made by another.
Try harder to use a source control system. Centralized systems like SVN that need to be hosted somewhere aren't the only option. Systems like git, allow you safely swap changes directly between team members.

Which information (files) of an eclipse-workspace should be tracked by source control

I want to track the workspace of eclipse by source control so that important settings can be backed up. However, there are a lot of kind of *.index inside the .metadata folder of workspace. Some information are important, for example Mylyn repository, but some information is merely cached files and thus, doesn't make sense to me for being tracked.
In short, what files inside eclipse workspace that should be tracked so that I can restore the working workspace after problems (like meta data file deleted, etc.)
You should not track metadata by source control. Project settings are in .classpath,.settings and .project files/folders. Metadata folder holds only eclipse settings, local tasks, caches and indexes.