Export (0) Print
Expand All

Walkthrough: Debugging an Add-In Project

Add-ins are compiled applications that use the Visual Studio automation object model to manipulate or automate the integrated development environment (IDE). For more information, see Functional Automation Groups.

This walkthrough will show you how to:

  • Create a simple Visual Studio .NET Add-in project.
  • Use breakpoints to debug your Visual Studio Add-in project.

To create a simple Visual Studio Add-in project

  1. From the File menu, choose New and click Project.

    The New Project Dialog Box appears.

  2. In the Project Types pane, expand the Other Projects node and select Extensibility Projects. In the Templates pane, select Visual Studio .NET Add-in.
  3. In the Name field, enter SimpleAddIn as the name for your Add-in project. Click OK.

    The Add-in Wizard appears.

  4. In the Welcome to the Add-in Wizard page, click Next.
  5. In the Select a Programming Language page, choose Create an Add-in using Visual C# and click Next.
  6. In the Select an Application Host page, keep the default options and click Next.
  7. In the Enter a Name and Description page, enter Simple Add-in as the name for your Add-in and enter Used to illustrate how to debug a simple Add-in. as a description for your Add-in. Click Next.
  8. In the Choose Add-in Options page, check the option Yes, create a 'Tools' menu item., and then click Next.
  9. In the Choosing 'Help About' Information page, check the option Yes, I would like my Add-in to offer 'About' box information. and click Next.
  10. In the Summary page, click Finish.

    The Add-in Wizard generates your new Add-in project and opens the IDE with focus on the file Connect.cs.

  11. Add a reference to your assembly, to permit the use of types in System.Windows.Forms namespace. In Solution Explorer, right-click the References node and select Add Reference.

    The Add Reference Dialog Box will appear.

  12. In the .NET tab page, double-click the component System.Windows.Forms.dll. The name of this component will appear in the Selected Components pane.
  13. Click OK. In Solution Explorer, a reference to the System.Windows.Forms namespace appears under the References node.
  14. Add a using directive to permit use of a MessageBox object. In Connect.cs, add the following statement near the top of the SimpleAddIn scope:
    using System.Windows.Forms;
    
  15. Add a MessageBox object to your Add-in. Add the line of code in bold to the Exec method in Connect.cs:
    public void Exec(string commandName,
       EnvDTE.vsCommandExecOption executeOption,
       ref object varIn, ref object varOut, ref bool handled)
    {
       handled = false;
       if(executeOption ==
          EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
       {
          if(commandName == "MyAddin1.Connect.MyAddin1")
          {
             handled = true;
             MessageBox.Show("Debugging a Simple Add-in");
             return;
          }
       }
    }
    
  16. Click the Save All button to save your work.

To debug your Visual Studio Add-in project

  1. In Connect.cs, click in the left margin by the statement:
    MessageBox.Show("Debugging a Simple Add-in")
    

    A red dot (breakpoint) appears, and the text on this line is highlighted in red.

  2. From the Debug menu, choose Start. Your current Visual Studio session (the debugger session) will lose focus and the program being debugged (an instance of Visual Studio .NET) will open.
  3. From the Visual Studio IDE that is being debugged, open the Tools menu.

    SimpleAddIn is at the top of the menu items.

  4. Select the SimpleAddIn command to execute your Add-in. This takes you to the line where you set your breakpoint in the Visual Studio debugger session. This line is highlighted in yellow.
  5. From the Debug menu in the debugger session, Step Into. The focus will switch back to the debugged program. Your message box opens, indicating that your Add-in has been executed.
  6. Click OK to close your message box.
  7. In the debugger session, select Continue from the Debug menu. The debugged Visual Studio session will regain focus.
  8. Close the debugged Visual Studio session.
  9. In Connect.cs, click the breakpoint that you set next to the MessageBox statement to remove it from your source code.

See Also

Automation and Extensibility Reference | Debugging Samples and Walkthroughs

Show:
© 2014 Microsoft