project-system
project-system copied to clipboard
Debug profile launch target for json debug adapters
Is there a way or future plans for adding a launch target (Project Properties -> Debug -> Launch) that allows you to specify (or define inline) a json debug adapter file?
Not sure if I am even close to the correct names, However I'm referring to "DebugAdapterHost.Launch /LaunchJson:"<path-to-the-launch.json-file-you-saved>"" style commands.
I currently use the setup described in https://github.com/Microsoft/MIEngine/wiki/Offroad-Debugging-of-.NET-Core-on-Linux---OSX-from-Visual-Studio , however not having to remember and run the command would be a lot easier (from the "start debugging" section), by just allowing me to specify a custom debug profile that does that command when I click debug.
Maybe I am missing some builtin VS mechanism for this?
Tagging @gregg-miskelly from the debugger team. @csnewman What commands are you actually trying to run. As Gregg linked in that article there are easier ways to debug code running in a docker container, or over SSH to a linux machine.
As far as I know you can only attach over ssh, not directly launch? So following that guide I have a launch.json file that allows me to start the process and debug it in one action. The downside is that you have to invoke the launch.json file from the command window, instead of being able to use the standard debug profile functionality in VS.
I hacked together a solution that works for my limited use case:
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.Debug;
using Microsoft.VisualStudio.ProjectSystem.VS.Debug;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;
namespace JsonLaunchTarget
{
[Export(typeof(IDebugProfileLaunchTargetsProvider))]
[AppliesTo("LaunchProfiles")]
[Order(50)]
class JsonDebugLaunchTargetsProvider : IDebugProfileLaunchTargetsProvider
{
public Task OnAfterLaunchAsync(DebugLaunchOptions launchOptions, ILaunchProfile profile)
{
DTE2 dte = (DTE2)Package.GetGlobalService(typeof(SDTE));
dte.ExecuteCommand("DebugAdapterHost.Launch", $"/LaunchJson:\"{profile.ExecutablePath}\"");
return Task.CompletedTask;
}
public Task OnBeforeLaunchAsync(DebugLaunchOptions launchOptions, ILaunchProfile profile)
{
return Task.CompletedTask;
}
public async Task<IReadOnlyList<IDebugLaunchSettings>> QueryDebugTargetsAsync(DebugLaunchOptions launchOptions, ILaunchProfile profile)
{
return Array.Empty<IDebugLaunchSettings>();
}
public bool SupportsProfile(ILaunchProfile profile)
{
return profile.CommandName.Equals("JsonDebugAdapterLaunch");
}
}
}
This allows me to add a debug profile that uses a launch.json file as a launch target. Maybe this example clears up what I mean? (I am unfamiliar with VS extension development, so excuse the crude implementation)
Thanks - this isn't something that's on my radar to change in the short term, but I'll follow up with some folks on the debugger team to see what their thoughts are.
Glad that you have a workaround for now. Internally, @gregg-miskelly mentioned that writing this "properly" would me implementing QueryDebugTargetsAsync to return something like this:
debugTargetInfoValue.LaunchOperation = DebugLaunchOperation.CreateProcess;
debugTargetInfoValue.Executable = "dotnet";
debugTargetInfoValue.Options = real value should probably come from launchSettings.json, with maybe a few other things tacked on, but we want something like:
{
"name": ".NET Core Launch",
"request": "launch"
"type": "coreclr",
"$adapter": "c:\\mytools\\plink.exe",
"$adapterArgs": "-i c:\\users\\greggm\\ssh-key.ppk greggm@mylinuxbox -batch -T ~/vsdbg/vsdbg --interpreter=vscode",
"cwd": "~/clicon",
"program": "bin/Debug/netcoreapp1.0/clicon.dll",
}
debugTargetInfoValue.LaunchDebugEngineGuid = new Guid("{541B8A8A-6081-4506-9F0A-1CE771DEBC04}");
debugTargetInfoValue.Project = configuredProject.UnconfiguredProject.Services.HostObject as IVsHierarchy;
@csnewman I really like your idea of creating a VS extension. Would you mind sharing your complete code together with a tiny "How to use?" documentation? Would be awesome! Thanks!
EDIT: For everybody landing here looking for an easy way to start remote debugging: I created and published an extension which can help: https://github.com/LukeOwlclaw/RemoteDebugLauncher
It's been 5 years since this saw anything; the mentioned repository is no longer available and there really doesn't seem to be any consistent means for doing this to date. Has there been any further progress on supporting launch.json within VS launchSetting profiles? We specifically have containers running in multiple different environments (non-rootful podman, k8s, etc...) and would like to have a more developer friendly way to attach these debuggers or run these debugging sessions without having to open up the Command Window and paste in a static command.