[FIXED] On VS Code startup.. Connect automatically to WSL-Ubuntu, open project folders, and personal files

Issue

Earlier days..
My requirement: As soon as I open the VS Code, open these two together:
a. project folder(s) – development related
b. my personal text files like Notes.txt lying in some other folders

Answer:
Create a workspace
Add folder (my development project) to workspace
Open the personal text files
Save workspace
Next time on VS Code startup.. Just open this workspace

Nowadays..
My requirement: As soon as I open the VS Code (on startup), do these:
a. Connect automatically to WSL-Ubuntu
b. Open the remote project folder(s)
c. Open my personal text files

i.e. everything in a single VS Code instance.

I tried out several ways but of no avail. The main limitation is when I click the ‘Remote Connect’ manually, it opens a new VS Code instance which I don’t want.

Pl. guide how to achieve this.

Solution

VS-Code can be run in two environments:

a. Local: The VS Code is run in the Windows local environment. Open the files and folders using the path like D:\Project\business\Notes.txt

b. Remote: The VS Code is run in the WSL Ubuntu environment. Open the files and folders using the path like /mnt/d/Project/business/Notes.txt

Suppose that you have a file, already opened in the VS Code, whose path is D:\Project\business\Notes.txt. This means that it is a ‘local’ environment.

Now if you open another file using this path, /mnt/d/Project/business/api/main.ts, the VS Code will not open it in the same ‘local’ (existing VS Code instance) environment. Instead it starts another ‘remote’ VS Code instance and opens this file over there. It is because /mnt/d means that you want to open the Windows D drive in the ‘remote’ environment.

Inn other words, it means.. if you are working in a ‘remote’ environment, do not open the files and folders using the standard Windows path. Otherwise, a new VS window will be opened for you.

Answered By – cool

Answer Checked By – Marilyn (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published