无法从Visual Studio调试部分机器的远程Docker:VsDbgRemoteUnixLauncher仅支持远程Unix机器
在Ubuntu机器的Linux Docker容器中运行.NET 7应用,无法从Windows 11的Visual Studio附加调试,但能正常连接其他Ubuntu机器Docker里的.NET应用。
报错信息:
Failed to launch debug adapter 'coreclr'.
VsDbgRemoteUnixLauncher only supports remote Unix machines!
“附加到进程”向导能看到容器及其中的进程,说明SSH连接正常,但网上找不到该错误的相关信息。
执行命令DebugAdapterHost.Logging /On /OutputWindow后,调试适配器主机日志输出如下:
1> DebugAdapterHost version: 17.6.10530.1 commit:a8b80a80533cc2b91039497e292d6997b60501a6 1> ERROR: Failed to launch debug adapter! DebugAdapterLaunchException: Failed to launch debug adapter. Additional information may be available in the output window. Failure Location: LaunchingProcess Inner Exception: InvalidOperationException: VsDbgRemoteUnixLauncher only supports remote Unix machines! Microsoft.VisualStudio.Debugger.VsDbg.Integration.AdapterLauncher.VsDbgRemoteUnixLauncher.Microsoft.VisualStudio.Debugger.DebugAdapterHost.Interfaces.IAdapterLauncher.LaunchAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop) Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterProcessConnection..ctor(ConfigurationWrapper configuration, IDiagnosticLogger log, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop, IAdapterLauncher launcher) Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterHostFactory.CreateDebugAdapterHost(ConfigurationWrapper configuration, IDiagnosticLogger log, ExtensibilityManager extensibilityManager, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop, Boolean registerStandardHandlers, DebugProtocolOptions options, Action`1 syncRequestErrorHandler) 1> ERROR: Unexpected error DebugAdapterLaunchException: Failed to launch debug adapter. Additional information may be available in the output window. Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterHostFactory.CreateDebugAdapterHost(ConfigurationWrapper configuration, IDiagnosticLogger log, ExtensibilityManager extensibilityManager, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop, Boolean registerStandardHandlers, DebugProtocolOptions options, Action`1 syncRequestErrorHandler) Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterHostFactory.CreateDebugAdapterHost(DebuggedProcess process, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop) Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.Engine.Implementation.DebuggedProcess.StartDebugAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop) Failure Location: LaunchingProcess Inner Exception: InvalidOperationException: VsDbgRemoteUnixLauncher only supports remote Unix machines! Microsoft.VisualStudio.Debugger.VsDbg.Integration.AdapterLauncher.VsDbgRemoteUnixLauncher.Microsoft.VisualStudio.Debugger.DebugAdapterHost.Interfaces.IAdapterLauncher.LaunchAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop) Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterProcessConnection..ctor(ConfigurationWrapper configuration, IDiagnosticLogger log, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop, IAdapterLauncher launcher) Microsoft.VisualStudio.Debugger.VSCodeDebuggerHost.AdapterHosting.DebugAdapterHostFactory.CreateDebugAdapterHost(ConfigurationWrapper configuration, IDiagnosticLogger log, ExtensibilityManager extensibilityManager, IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop, Boolean registerStandardHandlers, DebugProtocolOptions options, Action`1 syncRequestErrorHandler) 1> ERROR: Failed to launch debug adapter. Additional information may be available in the output window. VsDbgRemoteUnixLauncher only supports remote Unix machines!
验证目标Ubuntu机器的系统标识
执行uname -a命令,确认输出的内核信息为标准Unix/Linux格式。若输出异常,需修复系统的操作系统标识配置,避免Visual Studio误判目标系统类型。重置Visual Studio远程调试缓存
- 关闭Visual Studio,删除
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\<你的VS版本号>\RemoteDebugger目录下的所有缓存文件 - 重新启动Visual Studio,重新添加远程Ubuntu机器的连接配置,确保选择的目标类型为Unix
- 关闭Visual Studio,删除
升级Visual Studio到最新稳定版
当前使用的DebugAdapterHost版本为17.6.10530.1,该版本可能存在适配bug。升级到Visual Studio 2022的最新版本,修复已知的远程调试兼容性问题。排查Docker容器网络配置
尝试将容器切换为host网络模式,再尝试附加调试,排除端口映射或网络隔离导致的调试请求异常。手动部署vsdbg调试工具
手动下载与Visual Studio版本匹配的vsdbg工具,放置到Ubuntu机器的~/.vs-debugger/vs2022目录,避免自动部署时出现版本不兼容或文件损坏问题。
内容的提问来源于stack exchange,提问作者Coder14

