WSL2: Launching VSCode from the command line using a *.code-workspace file

Viewed 227

I have Windows 10 + WSL2 with the latest version of VSCode. I also have a simple .code-workspace file which I can double-click (from within the windows file-explorer) and launch VSCode in a way that it pops-up already attached to a specific docker-container that is up-and-running.

This works great with double-clicking on the .code-workspace file:

{
    "folders": [
        {
            "uri": "vscode-remote://attached-container+7b2...27d/workspace/foobar"
        }
    ],
    "remoteAuthority": "attached-container+7b2...27d",
    "settings": {}
}

Apart from double-clicking I can also invoke VSCode from Windows command-line (dos) and this works ok too:

  "C:\Program Files\Microsoft VS Code\Code.exe" "C:\path\to\foobar.code-workspace"

However when I try to open the workspace from within WSL2:

  code ./foobar.code-workspace

Even though VSCode pops-up the workspace doesn't open properly. What should I do to make the WSL2 (bash) command-line work the same way as in Windows?

1 Answers

And to answer my own question:

  "/mnt/c/Program Files/Microsoft VS Code/Code.exe"   ./foobar.code-workspace

Strangely enough this does the trick.

To make the script a bit more dynamic I guess one could write something like:

  "$(which code | xargs -0 dirname | xargs -0 dirname)/Code.exe"  ./foobar.code-workspace

Hope this helps some folks out there save a few hours worth of time.

Related