Is there a way in Microsoft VS Code to create two files for settings.json (different names or different subfolder) and switch between them?
Background: We use the Java Extension in VS Code. Our source code repository contains the settings for a Java project in a Unix environment. In specific cases we want to run the code in Windows environment and need a different settings.json.
Is there a way in Microsoft VS Code to create two files for settings.json (different names or different subfolder) and switch between them?
Not by default- no.
You can wait for this feature-request gets implemented (though you might be waiting a while): Allow to scope settings by platform #5595. You can show your support for the issue ticket by giving a thumbs up reaction to the issue. But please don't make a "me too" comment. "me too" comments generally come off as annoying to repo maintainers because they clutter up discussion and don't contribute anything of significant value.
In the meantime, you could create a script to do so with your technology of choice and write a VS Code task to run the script, but that sounds like a footgun for accidental thrashy git changes. I'd instead suggest writing two template files named something like .vscode/settings.unix.json
and .vscode/settings.windows.json
and committing those to version control, but putting .vscode/settings.json
in the gitignore.
Certain other settings already have mechanisms to allow you have different values for different platforms: terminal profile definitions, and keybindings. But those are more user settings and not workspace settings.
You may also find the Profiles feature useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With