部署和安装 SharePoint 加载项：方法和选项Deploying and installing SharePoint Add-ins: methods and options
本文将详细介绍 SharePoint 加载项的发布选项，以及如何安装和卸载加载项。In this article, you'll learn more about the options for publishing your SharePoint Add-in, as well as how to install and uninstall it.
发布到 Office 应用商店或组织加载项目录Publishing to the Office Store or an organization's add-in catalog
您可以将 SharePoint 外接程序上载到公用 Office 商店或组织的专用外接程序目录。专用外接程序目录是 SharePoint Web 应用程序（或 SharePoint Online 租赁）中的一个专用网站集，用于托管 SharePoint 外接程序和 Office 外接程序的文档库。将该目录放入其自有网站集更便于 Web 应用程序管理员或租户管理员限制对该目录的权限。You can upload your SharePoint Add-in to either the public Office Store or to an organization's private add-in catalog. A private add-in catalog is a dedicated site collection in a SharePoint web application (or a SharePoint Online tenancy) that hosts document libraries for SharePoint Add-ins and Office Add-ins. Putting the catalog into its own site collection makes it easier for the web application administrator or tenant administrator to limit permissions to the catalog.
如果将外接程序上载到 Office 商店，Microsoft 会对其运行一些验证检查。例如，它会检查外接程序清单标记是否有效且完整，并验证包含的任何 SharePoint 解决方案包（.wsp 文件）不包括超过 Web 范围而不允许的元素或功能。还会检查包的内容是否存在不允许的内容。如果外接程序通过所有测试，则会将外接程序包打包到一个文件并由 Microsoft 签署。If the add-in is uploaded to the Office Store, Microsoft runs some validation checks on it. For example, it checks whether the add-in manifest markup is valid and complete and verifies that any SharePoint solution packages (.wsp files) that are included do not include disallowed elements or Features with a scope broader than Web. The content of the package is also inspected for objectionable content. If the add-in passes all tests, the add-in package is wrapped into a file and signed by Microsoft.
如果使用 Microsoft Visual Studio 的 Office 开发人员工具开发和部署加载项，加载项会直接安装到目标测试 SharePoint 网站中。When you are developing your add-in and deploying it with Microsoft Office Developer Tools for Visual Studio, the add-in is directly installed on the target test SharePoint site. 由于没有经历 Office 应用商店这一环节，因此不会进行上述验证检查。Because it is not passing through the Office Store, the validation checking described earlier does not occur.
将 SharePoint 加载项上传到组织加载项目录就像将任何文件上传到 SharePoint Foundation 文档库一样简单。Uploading a SharePoint Add-in to an organization's add-in catalog is as easy as uploading any file to a SharePoint Foundation document library. 只需填写弹出式表单，在其中提供加载项包的本地 URL 和其他信息（如加载项名称）即可。You fill out a pop-up form in which you supply the local URL of the add-in package and other information, such as the name of the add-in. 上传到组织加载项目录的加载项也会经历一些类似的检查，未通过检查的加载项在目录中标记为无效或已禁用。When the add-in is uploaded to an organization's add-in catalog, similar checks take place, and add-ins that do not pass are marked as invalid or disabled in the catalog.
租户管理员和 SharePoint Web 应用管理员可以在 Office 应用商店中购买 SharePoint 加载项。Tenant administrators and SharePoint web application administrators can shop for SharePoint Add-ins in the Office Store. 若要打开 Office 应用商店，管理员需要先选择“网站内容”**** 页上的“添加加载项”****，再选择“你的加载项”**** 页中的“SharePoint 商店”****。To open the Office Store, the administrator selects Add an Add-in on the Site Contents page and then selects SharePoint Store in the Your Add-ins page. 这会打开“SharePoint 商店”**** 页，管理员可以在其中发现并了解供应商提供的 SharePoint 加载项（也可以在 office.com 上这样做）。This opens a SharePoint Store page that the administrators can use to discover and learn about SharePoint Add-ins that vendors are offering (they can also do this on office.com).
如果管理员的 Web 应用或租赁中未安装加载项需要的必备组件，加载项会变暗，并且不可在加载项商店中购买。Add-ins that require a prerequisite that is not installed on the administrator's web application or tenancy appear dimmed and are unavailable in the add-in store. 例如，如果加载项需要的搜索服务未安装，那么加载项会变暗。For example, if an add-in requires Search Services and this is not installed, the add-in appears dimmed. 管理员可以对加载项列表进行排序、筛选和浏览，也可以了解加载项并查看加载项评论，同时还能购买加载项许可证。Administrators can sort, filter, and browse the list of add-ins, read about the add-ins, see add-in reviews, and purchase licenses for an add-in.
管理员在决定购买许可证时，必须接受购买的条款和条件，并同意执行该外接程序必须具备的权限，如对列表的读取访问权限或对网站集的完全控制访问权限。When an administrator decides to purchase a license, she must accept the terms and conditions of purchase and agree to the permissions that the add-in must have in order to execute, such as read access to lists or full control access to the site collection.
购买一个外接程序的一个或多个许可证时，许可证将下载到 Web 应用程序或租赁。尽管管理员可以选择一起进行安装和许可证购买，但购买许可证时不会自动下载并安装外接程序。When one or more licenses for an add-in are purchased, the licenses are downloaded to the web application or tenancy. The add-in is not automatically downloaded and installed when the license is purchased, although administrators have the option to combine installation with license purchase.
用户从"您的外接程序"页安装外接程序。此页面包含以下内容的合并列表：Users install add-ins from the Your Add-ins page. This page has a merged listing of the following:
- Web 应用（或租户）的组织加载项目录中的 SharePoint 加载项。SharePoint Add-ins from the web application's (or the tenant's) organization add-in catalog.
- Office 应用商店中的 SharePoint 加载项，组织或租户已拥有网站许可证或已分配给用户的许可证。SharePoint Add-ins from the Office Store for which the organization or tenant already owns a site license or a license that has been assigned to the user.
用户可立即安装的所有加载项都会列出。All the add-ins that the user can install immediately are listed. 用户可以从页面上的加载项中筛选出组织加载项目录中的加载项。Users can filter the add-ins included on the page to include only add-ins in the organization's add-in catalog. 已安装的加载项显示在“网站内容”**** 页上的加载项列表中（位于已安装到的网站上）。When an add-in is installed, it appears in the list of add-ins on the Site Contents page of the website to which it is installed.
安装 SharePoint 加载项Installing SharePoint Add-ins
Website owners install SharePoint Add-ins from the Your Add-ins page as described earlier in this topic. Installation creates an instance of the add-in. For more information about installing add-ins, see Add SharePoint Add-ins to a SharePoint site.Website owners install SharePoint Add-ins from the Your Add-ins page as described earlier in this topic. Installation creates an instance of the add-in. For more information about installing add-ins, see Add SharePoint Add-ins to a SharePoint site.
有时网络连接暂时丢失会阻止安装。不管任何原因导致安装失败，安装基础结构都会重试三次。如果不成功，用户界面中会指出（显示）安装失败。用户可以稍后重试安装。Sometimes a temporary loss of a network connection can block installation. If installation fails for any reason, the installation infrastructure will retry three times. If it does not succeed, an indication of the failure appears in the UI. Users can retry the installation later.
卸载 SharePoint 加载项Uninstalling SharePoint Add-ins
网站所有者可以通过 SharePoint UI 卸载 SharePoint 外接程序的实例。SharePoint 外接程序实例的卸载非常彻底。这意味着外接程序安装的所有内容都将卸载。Website owners can uninstall an instance of a SharePoint Add-in through the SharePoint UI. Uninstallation of an instance of a SharePoint Add-ins is clean. This means that everything installed by the add-in is uninstalled.
不过，加载项使用但与加载项分开安装的组件不会遭删除。However, components that an add-in uses, but that are installed separately from the installation of the add-in, are not removed. 例如，假设加载项有一个远程网页，其中包含在主机 Web 上创建列表的按钮。For example, suppose an add-in has a remote webpage with buttons that create lists on the host web. 卸载加载项会从“网站内容”**** 页中删除加载项磁贴，这反过来会导致最终用户实际无法访问或使用远程页面，但并不会删除通过加载项创建的列表。Uninstallation of the add-in removes the add-in's tile from the Site Contents page, which in turn makes the remote page effectively inaccessible or unusable for end users, but it does not remove the lists that were created with the add-in. 由于 SharePoint 没有记录哪些列表是通过加载项在主机 Web 上创建，哪些列表是由用户在 SharePoint UI 中创建，因此无法删除通过加载项创建的列表。SharePoint does not keep a record of which lists on the host web were created with the add-in and which ones were created by users in the SharePoint UI, so it can't delete lists that were created with the add-in. 这通常是理想行为，因为即使在删除创建了列表的加载项后，列表中的数据也可能仍对用户有用。This is generally desirable behavior because the lists may have data that remains useful to users even after the removal of the add-in that created the lists.
如果 SharePoint 外接程序包含一个外接程序 Web，则该外接程序 Web 将被删除。与系统地停用功能并还原到外接程序的内部 .wsp 文件的部署相比，这种卸载方式更为彻底。If the SharePoint Add-in includes an add-in web, the add-in web is deleted. This provides a cleaner uninstall than systematically deactivating features and reversing the deployment of the add-in's internal .wsp file.
用户删除的加载项会移到第一阶段回收站。When a user removes an add-in, it is moved to the first stage Recycle Bin. 如果从第一阶段回收站中删除加载项，它会移到第二阶段回收站。Deleting it from there moves it to the second stage Recycle Bin. 如果从第二阶段回收站中删除加载项，它会彻底卸载，且无法还原。If it is deleted from the second stage Recycle Bin, it is completely uninstalled and cannot be restored.
加载项的权限也会随加载项删除（回收）一起撤消，具体规则如下：The add-in's permissions are also revoked when it is removed (recycled), according to these rules:
- Web 范围内的权限将始终被吊销。Web-scoped permissions are always revoked.
- 如果网站集中没有外接程序的任何其他实例，则网站集范围内的权限也将被吊销。If there is no other instance of the add-in in the site collection, site collection-scoped permissions are also revoked.
- 如果网站订阅（租赁）中没有其他任何加载项实例，租户范围权限也会随之撤消。If there is no other instance of the add-in in the site subscription (tenancy), tenant-scoped permissions are also revoked.
如果已在加载项的加载项清单中注册 UninstallingEventEndpoint Web 服务，它便从卸载过程一开始就执行（一直到从第二阶段回收站中删除加载项为止）。The UninstallingEventEndpoint web service, if one is registered in the add-in manifest of the add-in, executes at the beginning of the uninstallation process (which occurs when the add-in is removed from the second stage Recycle Bin). 根据最佳做法，如果有 InstalledEventEndpoint Web 服务，最好也有 UninstallingEventEndpoint Web 服务；最好将 UninstallingEventEndpoint 服务设计为，反向处理 InstalledEventEndpoint 服务完成的所有操作。It is a best practice to have an UninstallingEventEndpoint web service if you have an InstalledEventEndpoint web service and to design the UninstallingEventEndpoint service to reverse anything done in your InstalledEventEndpoint service. 有关详细信息，请参阅处理 SharePoint 加载项中的事件。For more information, see Handle events in SharePoint Add-ins.