visual-studio 如何通过 Visual Studio 调试 Sharepoint 解决方案/功能?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/2581193/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug Sharepoint solution/feature through Visual studio?
提问by pointlesspolitics
Recently I tried to install a webpart through wspbuilder utility to the Sharepoint Site. I have created, built and deployed a project to the 12 hive. After that installed the solution through Cental Administration Site and activated in the site collection.
最近我尝试通过 wspbuilder 实用程序将 webpart 安装到 Sharepoint 站点。我已经创建、构建并部署了一个项目到 12 hive。之后通过中央管理站点安装解决方案并在站点集中激活。
I just wonder how can I debug the complex feature/solution ? Because both processes (build-deploy and activate) totally independent, how can I attach a process with the worker process ?
我只是想知道如何调试复杂的功能/解决方案?因为两个进程(构建-部署和激活)完全独立,我如何将进程与工作进程附加?
采纳答案by Tom Clarkson
In the WSPBuilder context menu there is an option "Attach to IIS worker process". As long as the app is loaded (generally means that you have accessed a page in the SharePoint site before trying to attach) and the code deployed in SharePoint is the same as the code you have in Visual Studio, you should be able to set breakpoints and step through the code.
在 WSPBuilder 上下文菜单中有一个选项“附加到 IIS 工作进程”。只要应用程序已加载(通常意味着您在尝试附加之前访问了 SharePoint 网站中的页面)并且 SharePoint 中部署的代码与您在 Visual Studio 中的代码相同,您就应该能够设置断点并逐步执行代码。
回答by Jeroen Ritmeijer
Sometimes it is a bit of a pain to figure out which w3wp process to attach to. Try adding the following to your code to break into the debugger:
有时,弄清楚要附加到哪个 w3wp 进程有点麻烦。尝试将以下内容添加到您的代码中以进入调试器:
System.Diagnostics.Debugger.Break();
System.Diagnostics.Debugger.Break();
回答by jeremcc
First, you need to open up your browser and navigate to the SharePoint website in question. Then, In Visual Studio, go to Debug --> Attach to Process, and find the w3wp.exe process associated with the Sharepoint website that you want to debug. Click it (the process) and then click the Attach button. You should now be able to debug any activities associated with your SharePoint feature.
首先,您需要打开浏览器并导航到相关的 SharePoint 网站。然后,在 Visual Studio 中,转到调试 --> 附加到进程,然后找到与要调试的 Sharepoint 网站关联的 w3wp.exe 进程。单击它(进程),然后单击“附加”按钮。您现在应该能够调试与您的 SharePoint 功能相关联的任何活动。
回答by Punit Vora
System.Diagnostics.Debugger.Break()
Like Muhimbi suggested, this is actually very useful in certain cases. Say you want to debug custom code (e.g. feature_deactivating event) when it might be invoked with stsadm and not the browser. (for e.g. you will have to use stsadm for feature deactivation when feature is hidden in UI).When using stsadm you cannot attach to cmd.exe because that's a separate process. If you type the command and hit enter and then find its id of stsadm.exe process to attach to, its too late. In situations like these, the command above is the easist and best solution
就像 Muhimbi 建议的那样,这在某些情况下实际上非常有用。假设您想调试自定义代码(例如 feature_deactivation 事件),它可能会被 stsadm 而不是浏览器调用。(例如,当功能隐藏在 UI 中时,您将不得不使用 stsadm 来停用功能。使用 stsadm 时,您无法附加到 cmd.exe,因为这是一个单独的过程。如果您键入命令并按回车键,然后找到要附加到的 stsadm.exe 进程的 ID,则为时已晚。在这种情况下,上面的命令是最简单和最好的解决方案
回答by Harish
I tried the steps as mentioned here
我尝试了这里提到的步骤
go to Debug --> Attach to Process, and find the w3wp.exe process associated with the Sharepoint website that you want to debug
转到调试 --> 附加到进程,然后找到与要调试的 Sharepoint 网站关联的 w3wp.exe 进程
But I get "Breakpoints will not be hit, no symbols have currently been loaded for this document". Should I have to register the custom deployed solution dll using GACUTIL ? Should I have to copy the PDB files at any particular location ? What am I missing here ?
但是我得到“不会命中断点,当前没有为此文档加载任何符号”。我是否必须使用 GACUTIL 注册自定义部署的解决方案 dll?我是否必须在任何特定位置复制 PDB 文件?我在这里错过了什么?

