I need to debug an application that is started from a one-click install. (VS 2010, Excel VSTO with Office 7). Based on login credentials supplied to the one-click installer
To force a breakpoint from code use:
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break();
Sometimes the application can't be started from Visual Studio but must be debugged. I use this code to check form inside the application if the Visual Studio is running and offer the possibility to attach it to the Visual Studio.
using System.Diagnostics;
....
// get debugger processes
Process[] procName1 = Process.GetProcessesByName("devenv");
// get remote debugging processes
Process[] procName2 = Process.GetProcessesByName("msvsmon");
// If Visual Studio or remote debug are running halt the application by showing a MessageBox and give opportunity to attach the debugger
if (procName1.Length > 0 || procName2.Length > 0)
{
if (MessageBox.Show(Application.Current.MainWindow, "Force breakpoint?", "Wait for debugger attach", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
// Force a breakpoint when the debugger became attached
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break(); // force a breakpoint
}
}