简体   繁体   English

Visual Studio 2012加载项 - 如何将调试器附加到进程

[英]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.

相关问题 Visual Studio - 以编程方式将调试器附加到远程进程 - Visual studio - Attach debugger to remote process - programatically 将流程附加到Visual Studio 2013中的调试器 - Attach process to debugger in Visual Studio 2013 进入调试器时,Visual Studio 2008,Excel加载项挂起 - Visual Studio 2008, excel add-in hangs when stepping in debugger 如何将调试器附加到除我在Visual Studio 2017中启动的其他进程之外? - How do I attach a debugger to other process than I start in Visual Studio 2017? 在Visual Studio 2012 Professional中创建Outlook 2007/2003加载项 - Create Outlook 2007/2003 add-in in Visual Studio 2012 Professional Visual Studio 2012设计Outlook 2003加载项 - Visual Studio 2012 design an Outlook 2003 add-in 是否有Visual Studio 2012 / VS11的自定义语言加载项? - Is there a custom language add-in for Visual Studio 2012 / VS11? 附加到Visual Studio上的进程 - Attach to process on Visual Studio 如何从Visual Studio加载项中获取正在运行的进程的堆栈跟踪? - How to get stack trace of a running process from within a Visual Studio add-in? 如何清除调试器输出窗口Visual Studio 2012 - How to clear debugger output window Visual Studio 2012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM