Open nerdo opened 5 years ago
You can put launch configs in your regular settings. @weinand is that also supported in the devcontainer.json settings?
Tasks has an open issue to add global tasks in settings, similar to what launch does: https://github.com/microsoft/vscode/issues/1435
@isidorn @sandy081 @chrmarti I think we could easily support this, but does it fit into the grand scheme of things?
Configuraiton service would have to be aware of it first.
Looks like this is to support machine level launches and tasks.
@isidorn I think debug launches are already supported if you add a launch in remote settings.json.
Hey, just wanted to bump this with a specific use case I have and can't easily solve without a janky workaround.
I'm using vscode on mac, and developing golang using a remote container. I want to be able to switch back and forth between running locally and running remotely.
Locally I have project-specific config for which version of go i'm using using gvm (but the specific implementation of this is not important), and I configure the go.gopath
and go.goroot
in my .vscode/settings.json
. This is a per-project setting in my local environment. When I launch the container, it bind mounts my project directory into the container, and so the .vscode
directory is mounted there. It then picks up the settings.json
settings for my local environment and therefore the wrong paths to the toolchain.
There are a few ways one could fix this, and you all know better than I do how best to implement it, I'd only suggest a few things:
I would imagine there being settings ordered like:
User settings > Remote Workspace (defaults) > Project settings > Remote Project overrides
Anyway, just wanted to share my thoughts. :)
Workaround:
I've been able to work around the issue by creating a second settings.json
file called container-settings.json
and changing my docker-compose.yml
file to bind mount this file over the settings.json
in the container.
---
version: '3.7'
services:
myservice:
build:
dockerfile: Dockerfile
context: .
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
volumes:
- "..:/workspace:cached"
- "../.vscode/container-settings.json:/workspace/.vscode/settings.json:ro"
command: /bin/sh -c "while sleep 1000; do :; done"
where my settings.json
contains:
{
"go.inferGopath": false,
"go.gopath": "<HOME>/.gvm/pkgsets/go1.12.16/dfi:/Users/jsimms/.gvm/pkgsets/go1.12.16/global",
"go.goroot": "<HOME>/.gvm/gos/go1.12.16"
}
and container-settings.json
contains:
{
"go.inferGopath": false,
}
It works as a hack but some users may not want to go or be unable to go through the trouble to set it up like this.
There is an undocumented feature in devcontainer.json where you can do exactly this and define your launch/tasks.json inline. They need to go in settings.launch and settings.tasks. These will then appear like they would if you defined them in the .vscode folder. For our team, this works well as we have opinionated settings defined at the devcontainer level and still allow each developer to have their own .vscode folder that isnt committed to source code.
Here is a example devcontainer.json with launch and tasks
{
"name": "example",
"dockerFile": "Dockerfile",
"containerEnv": {
"DOCKER_BUILDKIT": "1"
},
"customizations": {
"vscode": {
"extensions": [
"ms-vsliveshare.vsliveshare"
],
"settings": {
"editor.formatOnSave": true
}
}
},
"settings": {
"launch": {
"configurations": [
{
"name": "API Debug",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/user-api/api/UserApi/bin/Debug/net6.0/UserApi.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {}
}
]
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/user-api/api/UserApi/UserApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/user-api/api/UserApi/UserApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/src/user-api/api/UserApi/UserApi.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
}
"remoteUser": "vscode",
}
Currently I don't seem to know a good way to have container-specific settings, tasks, and launch configurations.
The closest thing to it is to set up settings.json, tasks.json, and launch.json in the workspace .vscode folder, but then it applies to the workspace when you open it normally.
It would be ideal if we could have those same files in the .devcontainer folder and have vscode pick them up from there when the folder is opened in the container.
Currently the closest thing to it is in .devcontainer/devcontainer.json, there is a settings key which is similar to having settings.json, but i don't see anything for tasks or launch.