There are several options to alleviate cross-platform compabilitity issues.
-
Docker or container based - using containers as development machines allows developers to get started with minial setup and and abstrats the development environment from the host OS by having it run in a container.
- Running VS Code in a Docker container and using Dev Containers can also help in standardizing the local developer experience across the team.
- Follow a tutorial on Development in Containers
- For samples projects and dev container templates see VS Code Dev Containers Recipe
- Dev Containers Library
-
The example below shows the tasks system in VS Code which provides options to allow commands to be executed specific to an operating system.
The example below offers insight into running Node.js executable as a command with tasks.json and how it can be treated differently on Windows and Linux.
{
"label": "Run Node",
"type": "process",
"windows": {
"command": "C:\\Program Files\\nodejs\\node.exe"
},
"linux": {
"command": "/usr/bin/node"
}
}
In this example, to run Node.js, there is a specific windows command and a specific linux command. This allows for platform specific properties. When these are defined, they will be used instead of the default properties when the command is executed on the Windows operating system or on Linux.
Not all scripts or tasks can be auto-detected in the workspace. It may be necessary at times to defined your own custom tasks. In this example, we have a script to run in order to set up some environment correctly. The script is stored in a folder inside of your workspace and named test.sh for Linux & macOS and test.cmd for Windows. With the tasks.json file, the execution of this script can be made possible with a custom task that defines what to do on different operating systems.
{
"version": "2.0.0",
"tasks": [
{
"label": "Run tests",
"type": "shell",
"command": "./scripts/test.sh",
"windows": {
"command": ".\\scripts\\test.cmd"
},
"group": "test",
"presentation": {
"reveal": "always",
"panel": "new"
}
}
]
}
The command here is a shell command and tells the system to run either the test.sh or test.cmd. By default, it will run test.sh with that given path. This example here also defines Windows specific properities and tells it execute test.cmd instead of the default.
VS Code Docs - operating system specific properties