Skip to content

Find a way to auto-attach Unity debugger #29

@JonnyOThan

Description

@JonnyOThan

https://developercommunity.visualstudio.com/t/Provide-a-way-to-automate-attaching-Unit/10498892?space=8&q=unity+tools+autocomplete

Seems like it requires a vs extension:

// All needed types are in Microsoft.VisualStudio.Shell.Interop namespace
var debugger = (IVsDebugger4)GetService(typeof(IVsDebugger));

// We need to pass a special type to 'bstrOptions' below
const string prefix = "SyntaxTree.VisualStudio.Unity";
var debuggerHostAssembly = AppDomain.CurrentDomain.GetAssemblies(). First(a => a.GetName(). Name == prefix);
var debuggerHostType = $"{prefix}. Debugger.DebugEngineHost, {debuggerHostAssembly.FullName}";

// you can add several targets if you want
var targets = new VsDebugTargetInfo4[1];

targets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION. DLO_Custom;
targets[0].bstrExe = "Unity";
targets[0].fSendToOutputWindow = true;
targets[0].guidLaunchDebugEngine = new Guid("F18A0491-A310-4822-B12F-12CC30404EEC"); // this is the Unity Debugger Engine Guid
targets[0].bstrOptions = $"127.0.0.1:56872|{debuggerHostType}";                      // ip/port of the local or remote Editor/Player

// Attach to targets
var results = new VsDebugTargetProcessInfo[targets. Length];
debugger. LaunchDebugTargets4((uint)targets. Length, targets, results);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions