2

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?

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

0

At the end of the day wsl is installed on top of a windows environment you could also a .bat or .ps1 file and adds the commands they require without the need for the workspace. For example I have my script like this: wsl (cd ~/Projects; code ./test; command3; command4) exit inside the parentheses put all the commands you need and exit closes the terminal

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.