Attaching to WSL process from a visual studio extension.

Kev Martin 0 Reputation points
2025-06-02T10:10:24.7433333+00:00

I can attach to a WSL process in visual studio by going Debug -> 'Attach To Process' in the menu, then setting the 'Connection type' to 'Windows subsystem for Linux', selecting the process from the list, and clicking the 'attach' button.

How can I do this from inside a VSIX extension? Presumably I use IVsDebugger4.LaunchDebugTargets4(). But How do I configure it to attach to WSL?

Thanks for any help.

Developer technologies | Visual Studio | Extensions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Surya Amrutha Vaishnavi Lanka (INFOSYS LIMITED) 0 Reputation points Microsoft External Staff
    2025-07-04T10:49:13.5633333+00:00

    To attach to WSL processes programmatically, you can approach this task by leveraging the existing functionality in Visual Studio. Here's a general guideline based on what you shared:

    1. Access the Debugger: You’ll want to work with the IVsDebugger interface, which provides methods to start debugging sessions.
    2. Configure the Connection Type: You need to specify Windows Subsystem for Linux (WSL) as the connection type. This is crucial because it directs the debugger to work with WSL.
    3. Attach to the Process: While LaunchDebugTargets4 is typically used for launching new debugging sessions, you will likely want to look into methods similar to AttachToProcess, making sure you can specify the WSL distribution you need to attach to.
    4. Set up the Configuration: Create a debug launch configuration that matches how you set it up in the Visual Studio UI. This includes specifying any necessary parameters for processes running inside the WSL environment. The exact details may depend on the SDK version and the specifics of the process you're debugging.
    0 comments No comments

  2. Anas Younis 0 Reputation points
    2025-07-04T20:38:11.09+00:00

    Yes, use IVsDebugger4.LaunchDebugTargets4(), and set it up like this:

    dlo = DLO_Attach

    bstrExe = "<your PID or exe>"

    bstrPortName = "SSH:wsl+<DistroName>" (e.g., SSH:wsl+Ubuntu)

    guidLaunchDebugEngine = appropriate engine CLSID (C++, .NET Core, etc.)

    That bstrPortName is the key for WSL. Let me know if you need help with engine GUIDs or getting the distro name!


  3. Surya Amrutha Vaishnavi Lanka (INFOSYS LIMITED) 0 Reputation points Microsoft External Staff
    2025-07-07T08:04:41.8566667+00:00

    Hope you're doing well , we're following up on the ticket. Please let us know issue persist are resolved.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.