Partilhar via


Walkthrough: Debugging an Add-In Project

In Visual Studio 2013, add-ins are deprecated. We recommend that you upgrade your add-ins to VSPackage extensions. For more information about how to upgrade, see FAQ: Converting Add-ins to VSPackage Extensions.

This walkthrough illustrates how to create a basic Visual Studio add-in project and how to use breakpoints to debug it. For more information, see Breakpoints and Tracepoints.

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 Creating Add-ins and Wizards.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.

To create a basic Visual Studio add-in project

  1. On the menu bar, choose File, New, Project.

    The New Project Dialog Box appears.

  2. In the Project Types pane, expand Other Project Types, and then select Extensibility.

  3. In the Templates pane, select Visual Studio Add-in.

  4. In the Name field, type SimpleAddIn. Choose the OK button.

    The Add-in Wizard starts.

  5. On the Welcome to the Add-in Wizard page, choose the Next button.

  6. On the Select a Programming Language page, select Create an Add-in using Visual C#, and then choose Next.

  7. On the Select An Application Host page, accept the default options, and then choose Next.

  8. On the Enter a Name and Description page, type Simple Add-in as the name and Used to illustrate how to debug a simple Add-in. as the description. Choose Next.

  9. On the Choose Add-in Options page, select the Yes, create a 'Tools' menu item option, accept the remaining defaults, and then choose Next.

  10. On the Choosing 'Help About' Information page, select the Yes, I would like my Add-in to offer 'About' box information. option, and then choose Next.

  11. On the Summary page, choose the Finish button.

    The Add-in Wizard generates your new add-in project and opens the Connect.cs file. This is the main class that contains the code for your add-in.

  12. In Solution Explorer, on the shortcut menu for the project, choose Add, References, and then choose the Add New Reference button.

    This permits the use of types in the System.Windows.Forms namespace.

    The Add Reference dialog box appears.

  13. On the .NET tab, select System.Windows.Forms.dll and then choose the OK button.

    In Solution Explorer, a reference to the System.Windows.Forms namespace is displayed under the References node.

    This namespace contains the code that's required to display a Message Box, which is used in the following code example.

  14. In Connect.cs, add the following statement near the top of the SimpleAddIn scope to permit easier use of a MessageBox object:

    using System.Windows.Forms;
    
  15. Add a MessageBox object to your add-in by adding MessageBox.Show("Debugging a Simple Add-in"); to the Exec method:

    public void Exec(string commandName,
       vsCommandExecOption executeOption,
       ref object varIn, ref object varOut, ref bool handled)
    {
       handled = false;
       if(executeOption ==
          vsCommandExecOption.vsCommandExecOptionDoDefault)
       {
          if(commandName == "MyAddin1.Connect.MyAddin1")
          {
             handled = true;
             MessageBox.Show("Debugging a Simple Add-in");
             return;
          }
       }
    }
    
  16. Choose 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 (which symbolizes a breakpoint) is displayed, and the text on this line is highlighted in red.

  2. On the menu bar, choose Debug, Start Debugging.

    Your current Visual Studio session—the debugger session—will lose focus, and the program being debugged will open in another instance of Visual Studio.

  3. On the menu bar in the debugging instance of Visual Studio, choose Tools, SimpleAddIn to run the add-in.

    This takes you to the breakpoint that you set.

  4. On the menu bar in the debugging instance, choose Debug, Step Into.

    The focus switches back to the debugged program. Your message box opens, and indicates that your add-in has been executed.

  5. Choose the OK button to close the message box.

  6. On the menu bar in the debugging instance, choose Debug, Continue.

    Close the debugging instance of Visual Studio.

  7. In Connect.cs, remove the breakpoint next to the MessageBox statement.

See Also

Other Resources

Creating Add-ins and Wizards

Automation and Extensibility Reference