public static bool InstallDebugger(IMessageLogger msg, bool force = false) { try { if (CheckInstalled() && !force) //Check if the debugger is already installed { return(true); } string location = typeof(MonoEngine).Assembly.Location; //Register the debugger assembly string regasm = @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe"; if (!Environment.Is64BitOperatingSystem) { regasm = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe"; } var p = new ProcessStartInfo(regasm, location); p.Verb = "runas"; p.RedirectStandardOutput = true; p.UseShellExecute = false; p.CreateNoWindow = true; Process proc = Process.Start(p); proc.WaitForExit(); if (proc.ExitCode != 0) { throw new UnauthorizedAccessException(); } //Add the regsitry stuff for VS using (RegistryKey config = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_Configuration)) { RegisterDebugEngine(location, config); } return(true); } catch (UnauthorizedAccessException) { msg.ErrorMessage("Unable to install " + DebuggerGuids.EngineName + " - Please run Visual Studio as administrator.", "Debugger installation"); } catch (Exception ex) { msg.ErrorMessage("An error ocurred while installing " + DebuggerGuids.EngineName + ": \"" + ex.Message + "\"", "Debugger installation"); } return(false); }
public void StartDebugging(Project project, IMessageLogger msg) { string file = GetOutputFile(project); string folder = GetOutputFolder(project); ServiceProvider serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_dte); IntPtr debugInfo = GetDebugInfo(string.Empty, file, folder); try { IVsDebugger debugger = (IVsDebugger)serviceProvider.GetService((typeof(SVsShellDebugger))); int launchResult = debugger.LaunchDebugTargets(1, debugInfo); Marshal.ThrowExceptionForHR(launchResult); } catch (Exception ex) { IVsUIShell uiShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell)); string message; uiShell.GetErrorInfo(out message); if (!string.IsNullOrEmpty(message)) { msg.ErrorMessage("Unable to start debugger: \"" + message + "\"", "Debugger"); } else if (!string.IsNullOrEmpty(ex.Message)) { msg.ErrorMessage("Unable to start debugger: \"" + ex.Message + "\"", "Debugger"); } } finally { if (debugInfo != IntPtr.Zero) { Marshal.FreeCoTaskMem(debugInfo); } } }