public int DebugLaunch(uint grfLaunch) { IVsDebuggableProjectCfg cfg = _pythonCfg as IVsDebuggableProjectCfg; if (cfg != null) { return(cfg.DebugLaunch(grfLaunch)); } return(VSConstants.E_NOTIMPL); }
public int DebugLaunch(uint grfLaunch) { if (PythonConfig.IsAppxPackageableProject()) { VsDebugTargetInfo2[] targets; int hr = QueryDebugTargets(out targets); if (ErrorHandler.Failed(hr)) { return(hr); } VsDebugTargetInfo4[] appPackageDebugTarget = new VsDebugTargetInfo4[1]; int targetLength = (int)Marshal.SizeOf(typeof(VsDebugTargetInfo4)); // Setup the app-specific parameters appPackageDebugTarget[0].AppPackageLaunchInfo.AppUserModelID = DeployAppUserModelID; appPackageDebugTarget[0].AppPackageLaunchInfo.PackageMoniker = DeployPackageMoniker; appPackageDebugTarget[0].AppPackageLaunchInfo.AppPlatform = VsAppPackagePlatform.APPPLAT_WindowsAppx; #if DEV14_OR_LATER // Check if this project contains a startup task and set launch flag appropriately IVsBuildPropertyStorage bps = (IVsBuildPropertyStorage)this.PythonConfig; string canonicalName; string containsStartupTaskValue = null; bool containsStartupTask = false; get_CanonicalName(out canonicalName); bps.GetPropertyValue("ContainsStartupTask", canonicalName, (uint)_PersistStorageType.PST_PROJECT_FILE, out containsStartupTaskValue); if (containsStartupTaskValue != null && bool.TryParse(containsStartupTaskValue, out containsStartupTask) && containsStartupTask) { grfLaunch |= (uint)__VSDBGLAUNCHFLAGS140.DBGLAUNCH_ContainsStartupTask; } #endif appPackageDebugTarget[0].dlo = (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AppPackageDebug; appPackageDebugTarget[0].LaunchFlags = grfLaunch; appPackageDebugTarget[0].bstrRemoteMachine = targets[0].bstrRemoteMachine; appPackageDebugTarget[0].bstrExe = targets[0].bstrExe; appPackageDebugTarget[0].bstrArg = targets[0].bstrArg; appPackageDebugTarget[0].bstrCurDir = targets[0].bstrCurDir; appPackageDebugTarget[0].bstrEnv = targets[0].bstrEnv; appPackageDebugTarget[0].dwProcessId = targets[0].dwProcessId; appPackageDebugTarget[0].pStartupInfo = IntPtr.Zero; appPackageDebugTarget[0].guidLaunchDebugEngine = targets[0].guidLaunchDebugEngine; appPackageDebugTarget[0].dwDebugEngineCount = targets[0].dwDebugEngineCount; appPackageDebugTarget[0].pDebugEngines = targets[0].pDebugEngines; appPackageDebugTarget[0].guidPortSupplier = targets[0].guidPortSupplier; appPackageDebugTarget[0].bstrPortName = targets[0].bstrPortName; appPackageDebugTarget[0].bstrOptions = targets[0].bstrOptions; appPackageDebugTarget[0].fSendToOutputWindow = targets[0].fSendToOutputWindow; appPackageDebugTarget[0].pUnknown = targets[0].pUnknown; appPackageDebugTarget[0].guidProcessLanguage = targets[0].guidProcessLanguage; appPackageDebugTarget[0].project = PythonConfig; // Pass the debug launch targets to the debugger IVsDebugger4 debugger4 = (IVsDebugger4)Package.GetGlobalService(typeof(SVsShellDebugger)); VsDebugTargetProcessInfo[] results = new VsDebugTargetProcessInfo[1]; IVsDebugger debugger = (IVsDebugger)debugger4; // Launch task to monitor to attach to Python remote process var sourceDir = Path.GetFullPath(PythonConfig.GetProjectProperty("ProjectDir")).Trim('\\'); var targetDir = Path.GetFullPath(this.LayoutDir).Trim('\\'); var debugPort = PythonConfig.GetProjectProperty("RemoteDebugPort") ?? DefaultRemoteDebugPort; var debugId = Guid.NewGuid(); var serializer = new JavaScriptSerializer(); var debugCmdJson = serializer.Serialize(new string[] { "visualstudio_py_remote_launcher.py", debugPort.ToString(), debugId.ToString(), "--redirect-output" }); Debugger.PythonRemoteDebugEvents.Instance.RemoteDebugCommandInfo = Encoding.Unicode.GetBytes(debugCmdJson); Debugger.PythonRemoteDebugEvents.Instance.AttachRemoteProcessFunction = () => { return(RemoteProcessAttachAsync( appPackageDebugTarget[0].bstrRemoteMachine, debugId.ToString(), debugPort, sourceDir, targetDir)); }; int result = debugger.AdviseDebugEventCallback(Debugger.PythonRemoteDebugEvents.Instance); if (result == VSConstants.S_OK) { debugger4.LaunchDebugTargets4(1, appPackageDebugTarget, results); } else { Debug.Fail(string.Format(CultureInfo.CurrentCulture, "Failure {0}", result)); } return(result); } else { IVsDebuggableProjectCfg cfg = _pythonCfg as IVsDebuggableProjectCfg; if (cfg != null) { return(cfg.DebugLaunch(grfLaunch)); } return(VSConstants.E_NOTIMPL); } }