5

I have a scenario where when I start debugging a silverlight OOB project in visual studio the debugger attaches to that automatically, but it doesn't attach to the iisexpress process which is running the web service that the silverlight application connects to. It does start iisexpress but doesn't attach to it automatically. I have to manually go to Debug->Attach to process, find iisexpress and attach to it to debug both client and serverside code.

Since VS2012 removed macros I can't use that to automatically attach, so I'm trying to create a simple add-in to do it instead.

I'm stuck on how to attach to the process though. I've tried the following methods which both fire at the right time and find the iisexpress process, but all 3 give exceptions when trying to attach to it. Can anybody suggest how I can do this?

private void DebuggerEventsOnOnEnterRunMode(dbgEventReason reason)
{
    if (reason == dbgEventReason.dbgEventReasonLaunchProgram)
    {
        foreach (Process process in _applicationObject.Debugger.LocalProcesses)
        {
            var nameparts = process.Name.Split(Path.DirectorySeparatorChar);
            string name = nameparts[nameparts.Length - 1];
            if (name.Contains("iisexpress"))
                    process.Attach();  
                    // also tried: _applicationObject.ExecuteCommand("Debug.AttachToProcess", process.Name);
                    // and: _applicationObject.ExecuteCommand("Debug.AttachToProcess", name);
        }
    }
}
4

1 回答 1

4

适用于 VS 2010 和 VS 2012:

解决方案->右键单击->设置启动项目->多个启动项目

选择您的 2 个项目并在操作下将其设置为Start other than (for the 2nd project) possible Start without Debugging

于 2013-07-09T22:38:29.267 回答