Unable to debug WSL2 with VS 2022 - invalid 'cwd' value
Asked Answered
A

6

5

I am trying to debug from WSL2 using my VS 2022 IDE in Windows, but I get the following error:

Invalid cwd value

The cwd value does indeed look wrong, but how do I fix it?

I am using .netcore 6.0.101, Ubuntu 20.04.3 and Windows 11.

launchSettings.json:

{
  "profiles": {
    "WSL": {
      "commandName": "WSL2",
      "launchBrowser": false,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "local"
      },
      "applicationUrl": "https://localhost:56962;http://localhost:56963", 
      "distributionName": "Ubuntu"
    }
  }
}
PS C:\Users\me> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2
Adim answered 6/4, 2022 at 12:58 Comment(2)
Any progress on this?Wouldbe
@HrvojeJurić I don't think so, as I'm facing the same issue now. The funny thing is that VSCode (which is not an IDE) has WSL2 support, but Visual Studio does not.Conscription
C
3

This has been fixed in 17.4 Preview 5. The latest Preview releases are available for download here.

Ciapas answered 27/10, 2022 at 23:3 Comment(1)
Currently (28-10-2022) this has been fixed if you go through the network interface: \\wsl$\<distro>\some\path\here\to\solution. However if you have mapped the network interface \\wsl$\<distro>` to a specific network drive letter and load it through: Y:\some\path\here\to\solution` it still is brokenJudy
F
1

I tried to search some useful information for you, somebody said this is permisson issue. But I this below description is correct.

Currently the extension only support opening projects that are stored in the windows disks (it leverages WSLs automount feature).

Related Post: Debug Your .NET Core Apps in WSL 2 with Visual Studio

Fribourg answered 7/4, 2022 at 6:50 Comment(0)
L
1

In Visual Studio 2022:

Go to the project properties (right click on the project name in the Solution Explorer, then Properties on the pop up menu). Then, write in the search bar "working directory" and click on "Open debug launch profiles UI" here you'll find the "Working Directory" setting where you should set the wsl2 path you need.

Lucan answered 14/4, 2022 at 13:40 Comment(1)
Frustratingly, all I get from VS is "Waiting for Intellisense to finish initializing..." when I do this. Is there another place to set the wsl2 path?Adim
S
1

You have this error because Windows doesn't know about linux path used on WSL. But you can access your WSL2 directories on Windows using \\wsl$ path.

If your WSL2 machine name is Ubuntu, you need to define cwd value with following path:

\\wsl$\Ubuntu\home\<the_rest_of_the_path_you_need>
Subsolar answered 14/4, 2022 at 20:53 Comment(2)
Thanks for your answer but I do not know where to set the cwd value in this caseAdim
You can set the working directory in the launch profile. e.g. a .NET 6.0 project in /root/TestProject could use: "workingDirectory": "/root/TestProject", "executablePath": "dotnet", "commandLineArgs": "bin/Debug/net6.0/TestProject.dll"Ciapas
M
1

I could enter "\\wsl$" and "\\wsl.localhost" in File Explorer and it would open my remote Linux filesystem correctly, but for whatever reason, those paths would not resolve when I tried them in my workingDirectory field. So to get it working for me, I had to reference the path manually using a Linux POSIX-style path. If you reference the path like this, you will need to populate BOTH the workingDirectory field with the project path AND the commandLineArgs field with a relative path from the project path to the build's .dll file. Here is my full working example:

"WSL": {
  "commandName": "WSL2",
  "workingDirectory": "/home/username/path/to/project/directory",
  "launchBrowser": true,
  "launchUrl": "https://localhost:7056/swagger",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development",
    "ASPNETCORE_URLS": "https://localhost:7056;http://localhost:5183"
  },
  "commandLineArgs": "bin/Debug/net8.0orWhateverVersionYouAreUsing/projectName.dll"
}

I found a message here that explained how to do it.

Maximilien answered 29/1 at 17:29 Comment(0)
T
0

I've had the (almost) same error message ("Unknown Error: 0x8007001d" instead of "The system cannot find the path specified").

The reason was that I've opened the .sln file from a mounted path ("C:\Dev") which points to a Dev Drive ("D:") and seemingly the symlink Windows creates is not working properly in WSL.

I've worked around it by opening the solution directly from the Dev Drive "D:".

Thorbert answered 3/7 at 12:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.