[英]Visual studio 2012 add-in - how to attach debugger to a process
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. 我有一个场景,当我开始在visual studio中调试silverlight OOB项目时,调试器会自动附加到该项目,但它不会附加到运行silverlight应用程序连接到的Web服务的iisexpress进程。 It does start iisexpress but doesn't attach to it automatically.
它确实启动iisexpress但不会自动附加到它。 I have to manually go to Debug->Attach to process, find iisexpress and attach to it to debug both client and serverside code.
我必须手动转到Debug-> Attach to process,找到iisexpress并附加到它来调试客户端和服务器端代码。
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. 由于VS2012删除了宏,我无法使用它自动附加,所以我试图创建一个简单的加载项来代替它。
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.
我尝试了以下方法,它们都在正确的时间触发并找到iisexpress进程,但是当尝试连接到它时,所有3个都给出了异常。 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);
}
}
}
Works for both VS 2010 & VS 2012: 适用于VS 2010和VS 2012:
Solution -> Right Click -> Set Startup Projects -> Multiple Startup Projects
解决方案 - >右键单击 - >设置启动项目 - >多个启动项目
Choose your 2 projects and under action set it to Start other than (for the 2nd project) possible Start Without Debugging . 选择你的2个项目并在操作下将其设置为Start (除了第二个项目)可能的Start Without Debugging 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.