InfoPath 2010 调试

原文地址:http://nikspatel.wordpress.com/2011/07/20/debug-browser-enabled-infopath-2010-forms-deployed-on-sharepoint-2010-using-visual-studio-2010/

Unlike typical SharePoint 2010 development with Visual Studio 2010, debugging browser based InfoPath 2010 forms code is never easy. InfoPath custom coding requires specific software like VSTA (Microsoft Visual Studio 2005 Tools for Applications) to write custom code and one of the biggest limitations of the VSTA is it doesn’t support attaching debugger. Without VSTA supporting inbuilt debugging of InfoPath Code, you have to go through series of manual workarounds to debug the code.

Although Microsoft has documented detailed blog on the InfoPath team blog on how to debug InfoPath forms code, there are several details missing and it may become frustrating experience if you can’t hit the breakpoint while debugging InfoPath 2010 code. There are couple of clarifications Microsoft blog is missing including setting correct compile settings in the visual studio configuration manager. Without correct configuration manager setting as Active(Debug), even though project settings display debug for build settings, VSTA compiles code in the release mode which would further frustrate the developer if breakpoint never gets hit during debugging.

Based on lessons learned, I have finally decided to write detailed step by step blog to debug InfoPath 2010 Forms using Visual Studio 2010. Please keep in mind that to debug the browser based InfoPath forms, you will have to attach the SharePoint process in the Visual Studio, not Visual Studio Tools for Applications. Any version of Visual Studio is fine – VS 2005, VS 2008, or VS 2010.

Microsoft Resources

Here are the high level steps.

Step 1 – Ensure the InfoPath Form Template is compiled in the Debug Configuration so the XSN includes the symbol (PDB) file.

You must configure Visual Studio Tools for Applications (VSTA) to build PDB files for your form solution by outputting full debug information.

  • 1A – Open the InfoPath form template in the Design Mode using InfoPath Designer 2010
  • 1B – Open the code editor from the “Developer” Tab in the InfoPath Designer 2010. This will open the code files in the using Visual Studio Tools for Applications.
  • 1C – Verify that VSTA debugging options are enabled
    • Visit the Tools -> Options -> Projects and Solutions and make sure “Show Advanced Build Configuration” is checked.

    • Visit the Tools -> Options -> Debugging and make sure Enable “Just My Code (Managed Only)” and “Suppress JIT Optimization on module load (Managed Only)” Options are checked.

  • 1D - Make sure you have Active(Debug) configured from the Build Configuration Manager => Build -> Configuration Manager
    • Set Active Solution Configuration – Debug
    • Set Active Solution Platform – Any CPU

  • 1E – Verify Project Debugging Options are properly configured to Active (Debug) from the projects properties window by right clicking, Project -> Properties.
    • On the Build Tab -> Set Configuration to Debug and Advanced -> Debug Info to Full. If you see only Debug option and missing Active (Debug) as configuration options, please ensure that Debug is configured on the Configuration Manager as described on previous step.

    • On the Debug Tab -> Set Configuration to Active (Debug)

    • Compile the InfoPath Code in debug mode to include the PDB files
    • Verify that DLL and PDB files are created in the \bin\debug folder

Step 2 – Publish the InfoPath Form and verify that XSN file contains the debugged version of the compiled code.

Rename the XSN files to the CAB file to extract the InfoPath Form Template files and it should contain the debug version of the DLL and PDB files

Step 3 – Deploy the Debugged Version of InfoPath Form Templates to the SharePoint 2010

Step 4 – Debug the InfoPath Form Code through Visual Studio, not  VSTA

  • 4A – Open the browser and browse to the SharePoint site where forms are deployed. This will fire up the IIS worker process which needs to be attached to the Visual Studio for the debugging.
  • 4B – Open the FormCode.cs in the Visual Studio 2010

  • 4C – Attach w3wp Process from the Debug -> Attach to Process menu in the Visual Studio 2010. Make sure show all the processes from all the sessions and all the users are checked. Additionally, Make sure “Managed” is selected in Visual Studio 2008 and “Managed (v2.0, v1.1, v1.0) code” is selected in Visual Studio 2010.

  • 4D – Set the breakpoint in the code where you want to debug
  • 4E – Run the Browser based InfoPath form to execute the process that will cause the breakpoint to be hit. Congratulations. You are all set.

Hope this helps to clarify the steps needed to debug the InfoPath 2010 code deployed to the SharePoint 2010 environment.

 

 

 

你可能感兴趣的:(Path)