在 Visual Studio 中创建和调试 Office 外接程序Create and debug Office Add-ins in Visual Studio

本文介绍如何使用 Visual Studio 2017 为 Excel、Word、PowerPoint 或 Outlook 创建 Office 外接程序,并在 Windows 上的 Office 桌面客户端中调试外接程序。This article describes how to use Visual Studio 2017 to create an Office Add-in for Excel, Word, PowerPoint, or Outlook and debug the add-in in the Office desktop client on Windows. 如果使用的是 Visual Studio 的其他版本,操作步骤可能略有不同。If you're using another version of Visual Studio, the procedures might vary slightly.

备注

Visual Studio 不支持为 OneNote 或 Project 创建 Office 外接程序,但你可以使用 Office 外接程序的 Yeoman 生成器来创建这些类型的外接程序。Visual Studio does not support creating Office Add-ins for OneNote or Project, but you can use the Yeoman generator for Office Add-ins to create these types of add-ins.

先决条件Prerequisites

在 Visual Studio 中创建外接程序项目Create the add-in project in Visual Studio

首先完成以下三个步骤,然后完成后续部分中与你正在创建的外接程序类型相对应的步骤。Start by completing these three steps, and then complete the steps in the following section that corresponds to the type of add-in you're creating.

  1. 打开 Visual Studio,在 Visual Studio 菜单栏中,依次选择“文件” > “新建” > “项目”。Open Visual Studio and from the Visual Studio menu bar, choose File > New > Project.

  2. Visual C#Visual Basic 下的项目类型列表中,展开 Office/SharePoint,选择“外接程序”,然后选择要创建的外接程序项目的类型。In the list of project types under Visual C# or Visual Basic, expand Office/SharePoint, choose Add-ins, and then choose the type of add-in project you want to create.

  3. 命名此项目,然后选择“确定”。Name the project, and then choose OK.

Word Web 外接程序或 Outlook Web 外接程序Word Web Add-in or Outlook Web Add-in

如果你已选择创建 Word Web 外接程序Outlook Web 外接程序,Visual Studio 将创建一个解决方案,并在“解决方案资源管理器”中显示这两个项目。If you've chosen to create a Word Web Add-in or an Outlook Web Add-in, Visual Studio creates a solution and its two projects appear in Solution Explorer. 接下来,你可以浏览 Visual Studio 解决方案Next, you can explore the Visual Studio solution.

PowerPoint Web 外接程序PowerPoint Web Add-in

如果你已选择创建 PowerPoint Web 外接程序,则会出现“创建 Office 外接程序”对话框。If you've chosen to create a PowerPoint Web Add-in, the Create Office Add-in dialog appears.

  • 若要创建任务窗格外接程序,请选择“向 PowerPoint 添加新功能”,然后选择“完成”按钮以创建 Visual Studio 解决方案。To create a task pane add-in, select Add new functionalities to PowerPoint and then choose the Finish button to create the Visual Studio solution.

  • 若要创建内容外接程序,请选择“向 PowerPoint 幻灯片插入内容”,然后选择“完成”按钮以创建 Visual Studio 解决方案。To create a content add-in, select Insert content into PowerPoint slides and then choose the Finish button to create the Visual Studio solution.

接下来,你可以浏览 Visual Studio 解决方案Next, you can explore the Visual Studio solution.

Excel Web 外接程序Excel Web Add-in

如果你已选择创建 Excel Web 外接程序,则会出现“创建 Office 外接程序”对话框。If you've chosen to create an Excel Web Add-in, the Create Office Add-in dialog appears.

  • 若要创建任务窗格外接程序,请选择“向 Excel 添加新功能”,然后选择“完成”按钮以创建 Visual Studio 解决方案。To create a task pane add-in, select Add new functionalities to Excel and then choose the Finish button to create the Visual Studio solution.

  • 若要创建内容外接程序,请选择“向 Excel 电子表格插入内容”,选择“下一步”按钮,选择以下选项之一,然后选择“完成”按钮以创建 Visual Studio 解决方案:To create a content add-in, select Insert content into Excel spreadsheets, choose the Next button, select one of the following options, and then choose the Finish button to create the Visual Studio solution:

    • 基本外接程序 - 使用最少的入门代码创建内容外接程序项目Basic Add-in - to create a content add-in project with minimal starter code

    • 文档可视化外接程序 - 使用入门代码创建内容外接程序项目,以实现可视化并绑定到数据Document Visualization Add-in - to create a content add-in project with starter code to visualize and bind to data

浏览 Visual Studio 解决方案Explore the Visual Studio solution

在用户完成向导后,Visual Studio 会创建一个包含两个项目的解决方案。When you've completed the wizard, Visual Studio creates a solution that contains two projects.

项目Project 说明Description
加载项项目Add-in project 仅包含 XML 清单文件,其中包含描述加载项的全部设置。这些设置有助于 Office 主机确定应何时激活加载项,以及应在何处显示加载项。Visual Studio 会生成此文件的内容,以便用户能够立即运行项目并使用加载项。可以随时更改这些设置,具体方法是修改 XML 文件。Contains only an XML manifest file, which contains all the settings that describe your add-in. These settings help the Office host determine when your add-in should be activated and where the add-in should appear. Visual Studio generates the contents of this file for you so that you can run the project and use your add-in immediately. You change these settings any time by modifying the XML file.
Web 应用项目Web application project 包含加载项的内容页,包括开发 Office 感知 HTML 和 JavaScript 页面所需的全部文件和文件引用。开发加载项时,Visual Studio 在本地 IIS 服务器上托管 Web 应用。准备好发布加载项后,需要将此 Web 应用项目部署到 Web 服务器。Contains the content pages of your add-in, including all the files and file references that you need to develop Office-aware HTML and JavaScript pages. While you develop your add-in, Visual Studio hosts the web application on your local IIS server. When you're ready to publish the add-in, you'll need to deploy this web application project to a web server.

修改外接程序设置Modify your add-in settings

若要修改外接程序的设置,请编辑外接程序项目中的 XML 清单文件。To modify the settings of your add-in, edit the XML manifest file in the add-in project. 在“解决方案资源管理器”中,展开外接程序项目节点,展开包含 XML 清单的文件夹并选择 XML 清单。In Solution Explorer, expand the add-in project node, expand the folder that contains the XML manifest, and choose the XML manifest. 你可以指向该文件中的任何元素以查看说明该元素用途的工具提示。You can point to any element in the file to view a tooltip that describes the purpose of the element. 有关清单文件的详细信息,请参阅 Office 外接程序 XML 清单For more information about the manifest file, see Office Add-ins XML manifest.

开发外接程序的内容Develop the contents of your add-in

加载项项目允许您修改描述加载项的设置,而 Web 应用程序提供加载项中显示的内容。While the add-in project lets you modify the settings that describe your add-in, the web application provides the content that appears in the add-in.

Web 应用程序项目包含可用于实现入门的默认 HTML 文件、JavaScript 文件和 CSS 文件。The web application project contains a default HTML file, JavaScript file, and CSS file that you can use to get started. 其中一些文件包含对其他 JavaScript 库的引用,包括适用于 Office 的 JavaScript API。Some of these files contain references to other JavaScript libraries including the JavaScript API for Office. 你可以通过更新这些文件和/或添加更多 HTML 和 JavaScript 文件来开发外接程序。You can develop your add-in by updating these files and/or adding more HTML and JavaScript files. 下表描述了创建 Visual Studio 解决方案时 Web 应用程序项目包含的默认文件。The following table describes the default files that the web application project contains when the Visual Studio solution is created.

文件名File name 说明Description
Home.htmlHome.html
(Excel、PowerPoint、Word)(Excel, PowerPoint, Word)

MessageRead.htmlMessageRead.html
(Outlook)(Outlook)
外接程序的默认 HTML 页面。The default HTML page of the add-in. 在文档、电子邮件或约会项目中激活该外接程序时,此页面将显示为外接程序内的第一个页面。This page appears as the first page inside of the add-in when it is activated in a document, email message, or appointment item. 此文件包含入门所需的所有文件引用。This file contains all of the file references that you need to get started. 你可以通过将 HTML 代码添加到此文件来开始开发外接程序。You can start developing your add-in by adding your HTML code to this file.
Home.jsHome.js
(Excel、PowerPoint、Word)(Excel, PowerPoint, Word)

MessageRead.jsMessageRead.js
(Outlook)(Outlook)
Home.html 页面(Excel、PowerPoint、Word)或 MessageRead.html 页面 (Outlook) 关联的 JavaScript 文件。The JavaScript file associated with the Home.html page (Excel, PowerPoint, Word) or the MessageRead.html page (Outlook). 此文件应包含特定于 Home.html 页面(Excel、PowerPoint、Word)或 MessageRead.html 页面 (Outlook) 行为的任何代码。This file should contain any code that is specific to the behavior of the Home.html page (Excel, PowerPoint, Word) or the MessageRead.html page (Outlook). 此文件包含一些可帮你入门的示例代码。This file contains some example code to get you started.
Home.cssHome.css
(Excel、PowerPoint、Word)(Excel, PowerPoint, Word)

MessageRead.cssMessageRead.css
(Outlook)(Outlook)
定义要应用于外接程序的默认样式。Defines the default styles to apply to your add-in. 我们建议对设计和样式使用 Office UI Fabric。We recommend using the Office UI Fabric for design and styles. 有关详细信息,请参阅 Office 外接程序中的 Office UI FabricFor more information see Office UI Fabric in Office Add-ins.

备注

你无需使用这些文件。You don't have to use these files. 你可以随意将其他文件添加到项目并改为使用这些文件。Feel free to add other files to the project and use those instead. 如果要将另一个 HTML 文件显示为外接程序的初始页面,请打开清单编辑器,然后将 SourceLocation 属性设置为该文件的名称。If you want another HTML file to appear as the initial page of the add-in, open the manifest editor, and then set the SourceLocation property to the name of the file.

调试外接程序Debug your add-in

你可以使用 Visual Studio 在 Windows 上的 Office 桌面客户端中调试外接程序,如以下部分所述:You can use Visual Studio to debug your add-in in the Office desktop client on Windows, as described in the following sections:

备注

你无法使用 Visual Studio 在 Office Online 或 Office for Mac 中调试 Office 外接程序。You cannot use Visual Studio to debug Office Add-ins in Office Online or Office for Mac. 有关在这些平台上进行调试的信息,请参阅在 Office Online 中调试 Office 外接程序在 iPad 和 Mac 上调试 Office 外接程序For information about debugging on these platforms, see Debug Office Add-ins in Office Online or Debug Office Add-ins on iPad and Mac

查看生成和调试属性Review the build and debug properties

在开始调试之前,请检查每个项目的属性以确认 Visual Studio 将打开所需的主机应用程序,并已正确设置其他生成和调试属性。Before you start debugging, review the properties of each project to confirm that Visual Studio will open the desired host application and that other build and debug properties are set appropriately.

外接程序项目属性Add-in project properties

打开外接程序项目的“属性”窗口以查看项目属性:Open the Properties window for the add-in project to review project properties:

  1. 在“解决方案资源管理器”中,选择外接程序项目(而不是 Web 应用程序项目)。In Solution Explorer, choose the add-in project (not the web application project).

  2. 在菜单栏中,依次选择“视图” > “属性窗口”。From the menu bar, choose View > Properties Window.

下表介绍了外接程序项目的属性。The following table describes the properties of the add-in project.

属性Property 说明Description
启动操作Start Action 指定外接程序的调试模式。Specifies the debug mode for your add-in. 目前,Office 外接程序项目仅支持 Office 桌面客户端模式。Currently only Office Desktop Client mode is supported for Office Add-in projects.
启动文档Start Document
(仅限 Excel、PowerPoint 和 Word 外接程序)(Excel, PowerPoint, and Word add-ins only)
指定要在启动项目时打开的文档。Specifies what document to open when you start the project.
Web 项目Web Project 指定与外接程序关联的 Web 项目的名称。Specifies the name of the web project associated with the add-in.
电子邮件地址Email Address
(仅限 Outlook 外接程序)(Outlook add-ins only)
指定你想在 Exchange Server 或 Exchange Online 中用来测试 Outlook 外接程序的用户帐户的电子邮件地址。Specifies the email address of the user account in Exchange Server or Exchange Online that you want to use to test your Outlook add-in.
EWS UrlEWS Url
(仅限 Outlook 外接程序)(Outlook add-ins only)
Exchange Web 服务 URL(例如:https://www.contoso.com/ews/exchange.aspx)。Exchange Web service URL (For example: https://www.contoso.com/ews/exchange.aspx).
OWA UrlOWA Url
(仅限 Outlook 外接程序)(Outlook add-ins only)
Outlook Web App URL(例如,https://www.contoso.com/owa)。Outlook Web App URL (For example: https://www.contoso.com/owa).
使用多重身份验证Use multi-factor auth
(仅限 Outlook 加载项)(Outlook add-ins only)
布尔值,指示是否应使用多重身份验证。Boolean value that indicates whether multi-factor authentication should be used.
用户名User Name
(仅限 Outlook 外接程序)(Outlook add-ins only)
指定你想在 Exchange Server 或 Exchange Online 中用来测试 Outlook 外接程序的用户帐户的名称。Specifies the name of the user account in Exchange Server or Exchange Online that you want to use to test your Outlook add-in.
项目文件Project File 指定包含生成、配置和有关项目的其他信息的文件名称。Specifies the name of the file containing build, configuration, and other information about the project.
项目文件夹Project Folder 项目文件的位置。The location of the project file.

备注

对于 Outlook 外接程序,你可以选择在“属性”窗口中为一个或多个 Outlook 外接程序属性指定值,但这样做并不是必须的。For an Outlook add-in, you may choose to specify values for one or more of the Outlook add-in only properties in the Properties window, but doing so is not required.

Web 应用程序项目属性Web application project properties

打开 Web 应用程序项目的“属性”窗口以查看项目属性:Open the Properties window for the web application project to review project properties:

  1. 在“解决方案资源管理器”中,选择 Web 应用程序项目。In Solution Explorer, choose the web application project.

  2. 在菜单栏中,依次选择“视图” > “属性窗口”。From the menu bar, choose View > Properties Window.

下表介绍了与 Office 外接程序项目最相关的 Web 应用程序项目的属性。The following table describes the properties of the web application project that are most relevant to Office Add-in projects.

属性Property 说明Description
SSL 已启用SSL Enabled 指定是否在站点上启用 SSL。Specifies whether SSL is enabled on the site. 对于 Office 外接程序项目,此属性应设置为 TrueThis property should be set to True for Office Add-in projects.
SSL URLSSL URL 指定站点的安全 HTTPS URL。Specifies the secure HTTPS URL for the site. 只读。Read-only.
URLURL 指定站点的 HTTP URL。Specifies the HTTP URL for the site. 只读。Read-only.
项目文件Project File 指定包含生成、配置和有关项目的其他信息的文件名称。Specifies the name of the file containing build, configuration, and other information about the project.
项目文件夹Project Folder 指定项目文件的位置。Specifies the location of the project file. 只读。Read-only. Visual Studio 在运行时生成的清单文件将写入到此位置的 bin\Debug\OfficeAppManifests 文件夹中。The manifest file that Visual Studio generates at runtime is written to the bin\Debug\OfficeAppManifests folder in this location.

使用现有文档调试外接程序Use an existing document to debug the add-in

如果你有一个文档包含要在调试 Excel、PowerPoint 或 Word 外接程序时使用的测试数据,则可以将 Visual Studio 配置为在启动项目时打开该文档。If you have a document that contains test data you want to use while debugging your Excel, PowerPoint, or Word add-in, Visual Studio can be configured to open that document when you start the project. 若要指定在调试外接程序时要使用的现有文档,请完成以下步骤。To specify an existing document to use while debugging the add-in, complete the following steps.

  1. 在“解决方案资源管理器”中,选择外接程序项目(而不是 Web 应用程序项目)。In Solution Explorer, choose the add-in project (not the web application project).

  2. 从菜单栏中,选择“项目” > “添加现有项”。From the menu bar, choose Project > Add Existing Item.

  3. 在“添加现有项”对话框中,找到并选择要添加的文档。In the Add Existing Item dialog box, locate and select the document that you want to add.

  4. 选择“添加”按钮以将文档添加到项目中。Choose the Add button to add the document to your project.

  5. 在“解决方案资源管理器”中,选择外接程序项目(而不是 Web 应用程序项目)。In Solution Explorer, choose the add-in project (not the web application project).

  6. 在菜单栏中,依次选择“视图” > “属性窗口”。From the menu bar, choose View > Properties Window.

  7. 在“属性”窗口中,选择“启动文档”列表,然后选择添加到项目中的文档。In the Properties window, choose the Start Document list, and then select the document that you added to the project. 该项目现在配置为在该文档中启动外接程序。The project is now configured to start the add-in in that document.

启动项目Start the project

从菜单栏中依次选择“调试” > “开始调试”,可启动项目。Start the project by choosing Debug > Start Debugging from the menu bar. Visual Studio 将自动生成解决方案并启动 Office 以托管外接程序。Visual Studio will automatically build the solution and start Office to host your add-in.

备注

启动 Outlook 外接程序项目时,系统会提示你输入登录凭据。When you start an Outlook add-in project, you'll be prompted for login credentials. 如果系统要求你重复登录,或者如果收到指示未经授权的错误,则可能会禁用 Office 365 租户上帐户的基本身份验证。If you're asked to log in repeatedly or if you receive an error that you are unauthorized, then Basic Auth may be disabled for accounts on your Office 365 tenant. 在这种情况下,请尝试使用 Microsoft 帐户。In this case, try using a Microsoft account instead. 可能还需要在“Outlook Web 加载项”项目属性对话框中将属性“使用多重身份验证”设置为 True。You may also need to set the property "Use multi-factor auth" to True in the Outlook Web Add-in project properties dialog.

当 Visual Studio 生成项目时,它执行以下任务:When Visual Studio builds the project it performs the following tasks:

  1. 创建 XML 清单文件的副本并将其添加到 _ProjectName_\bin\Debug\OfficeAppManifests 目录。Creates a copy of the XML manifest file and adds it to _ProjectName_\bin\Debug\OfficeAppManifests directory. 启动 Visual Studio 并调试外接程序时,主机应用程序将使用此副本。The host application consumes this copy when you start Visual Studio and debug the add-in.

  2. 在计算机上创建一组允许外接程序在主机应用程序中显示的注册表项。Creates a set of registry entries on your computer that enable the add-in to appear in the host application.

  3. 生成 Web 应用程序项目,然后将其部署到本地 IIS Web 服务器 (https://localhost))。Builds the web application project, and then deploys it to the local IIS web server (https://localhost).

  4. 如果这是你已部署到本地 IIS Web 服务器的第一个加载项项目,系统可能会提示你将自签名证书安装到当前用户的受信任的根证书存储中。If this is the first add-in project that you have deployed to local IIS web server, you may be prompted to install a Self-Signed Certificate to the current user's Trusted Root Certificate store. 若要使 IIS Express 正确显示加载项内容,这是必需的操作。This is required for IIS Express to display the content of your add-in correctly.

备注

在 Windows 10 上运行时,最新版本的 Office 可能会使用较新的 Web 控件来显示加载项内容。The latest version of Office may use a newer web control to display the add-in contents when running on Windows 10. 如果是这种情况,Visual Studio 可能会提示你添加本地网络环回豁免。If this is the case, Visual Studio may prompt you to add a local network loopback exemption. 在 Office 主机应用程序中,需要这样做才能使 Web 控件访问部署到本地 IIS Web 服务器的网站。This is required for the web control, in the Office host application, to be able to access the website deployed to the local IIS web server. 还可以在 Visual Studio 中的“工具” > “选项” > “Office 工具(Web)” > “Web 加载项调试”下随时更改此设置****************。You can also change this setting anytime in Visual Studio under Tools > Options > Office Tools (Web) > Web Add-In Debugging.

接下来,Visual Studio 会执行以下操作:Next, Visual Studio does the following:

  1. 通过将 ~remoteAppUrl 标记替换为起始页的完全限定地址(例如,https://localhost:44302/Home.html)来修改 XML 清单文件的 SourceLocation 元素。Modifies the SourceLocation element of the XML manifest file by replacing the ~remoteAppUrl token with the fully qualified address of the start page (for example, https://localhost:44302/Home.html).

  2. 在 IIS Express 中启动 Web 应用程序项目。Starts the web application project in IIS Express.

  3. 打开主机应用程序。Opens the host application.

生成项目时,Visual Studio 不会显示“输出”窗口中的验证错误。Visual Studio doesn't show validation errors in the OUTPUT window when you build the project. Visual Studio 报告“错误列表”窗口中出现的错误和警告。Visual Studio reports errors and warnings in the ERRORLIST window as they occur. 通过在代码和文本编辑器中显示不同颜色的波浪下划线(称为波浪线),Visual Studio 还报告验证错误。Visual Studio also reports validation errors by showing wavy underlines (known as squiggles) of different colors in the code and text editor. 通过这些标志,你可以得知 Visual Studio 在你的代码中检测到的问题。These marks notify you of problems that Visual Studio detected in your code. 有关详细信息,请参阅代码和文本编辑器For more information, see Code and Text Editor. 有关如何启用或禁用验证的详细信息,请参阅选项、文本编辑器、JavaScript、IntelliSenseFor more information about how to enable or disable validation, see Options, Text Editor, JavaScript, IntelliSense.

要查看项目中 XML 清单文件的验证规则,请参阅 Office 外接程序 XML 清单To review the validation rules of the XML manifest file in your project, see Office Add-ins XML manifest.

调试 Excel、PowerPoint 或 Word 外接程序的代码Debug the code for an Excel, PowerPoint, or Word add-in

如果在启动项目后,在主机应用程序(Excel、PowerPoint 或 Word)中显示的文档中看不到外接程序,请在主机应用程序中手动启动外接程序。If your add-in isn't visible within the document that's displayed in the host application (Excel, PowerPoint, or Word) after you've started the project, manually launch the add-in in the host application. 例如,通过选择“主页”选项卡功能区中的“显示任务窗格”按钮来启动任务窗格外接程序。在 Excel、PowerPoint 或 Word 中显示外接程序后,你可以通过执行以下操作来调试代码:For example, launch your task pane add-in by choosing the Show Taskpane button in the ribbon of the Home tab. After your add-in is displayed in Excel, PowerPoint, or Word, you can debug your code by doing the following:

  1. 在 Excel、PowerPoint 或 Word 中,选择“插入”选项卡,然后选择“我的外接程序”右侧的向下箭头。In Excel, PowerPoint, or Word, choose the Insert tab and then choose the down-arrow located to the right of My Add-ins.

    Windows 版 Excel 的“插入”功能区及突出显示的“我的加载项”箭头

  2. 在可用外接程序列表中,找到“开发人员外接程序”部分并选择你的外接程序进行注册。In the list of available add-ins, find the Developer Add-ins section and select the your add-in to register it.

  3. 在 Visual Studio 中,在代码中设置断点。In Visual Studio, set breakpoints in your code.

  4. 在 Excel、PowerPoint 或 Word 中,与外接程序进行交互。In Excel, PowerPoint, or Word, interact with your add-in.

  5. 在 Visual Studio 中命中断点时,根据需要逐步执行代码。As breakpoints are hit in Visual Studio, step through the code as needed.

你可以更改代码并在外接程序中查看这些更改的效果,而无需关闭主机应用程序并重新启动该项目。You can change your code and review the effects of those changes in your add-in without having to close the host application and restart the project. 保存对代码的更改后,只需在主机应用程序中重新加载外接程序。After you save changes to your code, simply reload the add-in in the host application. 例如,通过选择任务窗格的右上角来激活个性菜单,然后选择“重新加载”,便可重新加载任务窗格外接程序。For example, reload a task pane add-in by choosing the top-right corner of the task pane to activate the personality menu and then choose Reload.

调试 Outlook 外接程序的代码Debug the code for an Outlook add-in

在你已启动项目,且 Visual Studio 启动 Outlook 来托管外接程序后,打开电子邮件或约会项目。After you've started the project and Visual Studio launches Outlook to host your add-in, open an email message or appointment item.

只要满足激活条件,Outlook 便会为项目激活外接程序。外接程序栏显示在"检查器"窗口或阅读窗格的顶部,Outlook 外接程序显示为外接程序栏中的一个按钮。如果您的外接程序有外接程序命令,那么在默认选项卡或指定的自定义选项卡中将有一个按钮显示在功能区中,而该外接程序将不会显示在外接程序栏中。Outlook activates the add-in for the item as long as the activation criteria are met. The add-in bar appears at the top of the Inspector window or Reading Pane, and your Outlook add-in appears as a button in the add-in bar. If your add-in has an add-in command, a button will appear in the ribbon, either in the default tab or a specified custom tab, and the add-in will not appear in the add-in bar.

若要查看 Outlook 外接程序,请选择对应 Outlook 外接程序的按钮。To view your Outlook add-in, choose the button for your Outlook add-in. 在 Outlook 中显示外接程序后,你可以通过执行以下操作来调试代码:After your add-in is displayed in Outlook, you can debug your code by doing the following:

  1. 在 Visual Studio 中,在代码中设置断点。In Visual Studio, set breakpoints in your code.

  2. 在 Outlook 中,与外接程序进行交互。In Outlook, interact with your add-in.

  3. 在 Visual Studio 中命中断点时,根据需要逐步执行代码。As breakpoints are hit in Visual Studio, step through the code as needed.

你可以更改代码并在外接程序中查看这些更改的效果,而无需关闭 Outlook 并重新启动该项目。You can change your code and review the effects of those changes in your add-in without having to close Outlook and restart the project. 保存对代码的更改后,只需打开外接程序的快捷菜单(在 Outlook 中),然后选择“重新加载”。After you save changes to your code, simply open the shortcut menu for the add-in (in Outlook), and then choose Reload.

后续步骤Next steps

在外接程序正常工作后,请参阅部署和发布 Office 外接程序,以了解可用于将外接程序分发给用户的方法。After your add-in is working as desired, see Deploy and publish your Office Add-in to learn about the ways you can distribute the add-in to users.