将 Office 加载项发布到 Microsoft AppSource ,使其广泛提供给客户和企业。 Microsoft AppSource 是一个在线商店,其中包含由行业领先的软件提供商构建的数千个业务应用程序和服务。 将外接程序发布到 Microsoft AppSource 时,还可以使其在 Office 中的产品内体验中可用。
发布过程
在继续作之前:
- 拥有 合作伙伴中心帐户。
- 确保加载项遵守适用的 AppSource 验证策略。
- 确认已 准备好发布。
准备好将解决方案包含在 Microsoft AppSource 和 Office 中时,请将其提交到合作伙伴中心。 然后,它将经历审批和认证过程。 有关完整详细信息,请参阅 使解决方案在 Microsoft AppSource 和 Office 中可用。
当加载项在 AppSource 中可用时,可以采取两个进一步的步骤来使其更广泛地安装。
提供安装链接
发布到 Microsoft AppSource 后,可以创建安装链接,帮助客户发现和安装加载项。 安装链接提供“单击并运行”体验。 将链接放在网站、社交媒体或你认为有助于客户发现加载项的任何位置。 当用户选择链接时,Office 应用程序将打开并显示一个新文档,并且已安装加载项,用户无需在 Microsoft AppSource 中搜索它并手动安装它。
注意
只能为 Excel、PowerPoint 和 Word 加载项创建安装链接。
有两种链接样式,具体取决于您希望 Office 应用程序在Office web 版中打开还是在桌面 Office 中打开。
注意
链接的样式仅确定打开的平台,而不能确定安装加载项的平台。 外接程序安装在支持其清单中指定的所有要求集的每个平台上。 请参阅 Office 版本和要求集。
在 Office web 版 中打开
若要创建链接,请使用以下 URL 模板作为参考。
https://go.microsoft.com/fwlink/?linkid={{linkId}}&templateid={{addInId}}&templatetitle={{addInName}}
更改 URL 中的占位符,如下所示。
linkId:指定打开新文档时要使用的 Web 终结点。
- 对于 web 上的Word:
2261098
- 对于Excel web 版:
2261819
- 对于PowerPoint web 版:
2261820
- 对于 web 上的Word:
addInId:AppSource 中列出的外接程序 ID。
addInName:外接程序的完整标题。 这必须是 URL 编码的。
例如,下面是Script Lab的安装链接。
以下参数值用于Script Lab安装链接。
-
linkid: 值
2261819
指定 Excel 终结点。 Script Lab支持 Word、Excel 和 PowerPoint,因此可以更改此值以支持不同的终结点。 -
templateid:该值
WA104380862
是Script Lab的 Microsoft AppSource ID。 -
templatetitle: 值
Script%20Lab,%20a%20Microsoft%20Garage%20project
是游戏的 URL 编码值。
在 Windows 或 Mac 上的 Office 中打开
若要创建链接,请使用以下 URL 模板作为参考。
{{appName}}:https://api.addins.store.office.com/addinstemplate/{{language}}/{{correlationID}}/{{addinId}}/none/{{addinName}}.{{fileFormat}}?omexsrctype=1&isexternallink=1
更改 URL 中的占位符,如下所示。
appName: 此参数指定当用户单击链接时打开哪个 Office 应用程序。
- 对于Word:
ms-word
- 对于 Excel:
ms-excel
- 对于 PowerPoint:
ms-powerpoint
- 对于Word:
语言: 这是加载项的语言。 例如:
de-DE
、ja-JP
或zh-CN
。correlationID: 用于诊断的 GUID。 例如,“7bf846ec-905a-5edd-b162-83498f9a8674”。 使用 GUID 生成工具。 如果多个用户具有相同的 GUID,则诊断目的会失败,因此我们建议在运行时生成它,并使其每次单击时有所不同。
addInId: AppSource 中列出的加载项 ID。 此参数区分大小写。 使用大写字母。
addInName: 外接程序的全名。 这必须是 URL 编码的。
fileFormat: 指定所创建文件的格式。
- 对于Word:
docx
- 对于 Excel:
xlsx
- 对于 PowerPoint:
pptx
- 对于Word:
例如,下面是 windows 上的 Word Script Lab 的安装链接,其中以 en-US 为语言。
ms-word:https://api.addins.store.office.com/addinstemplate/en-US/228a829b-69d7-45f4-a338-c6aba330ec7e/WA104380862/none/Script%20Lab,%20a%20Microsoft%20Garage%20project.docx?omexsrctype=1&isexternallink=1
在安装 Windows 应用或 COM/VSTO 外接程序时包括加载项
如果 Windows 应用或 COM 或 VSTO 加载项的功能与 Office Web 外接程序重叠,请考虑在安装 (或 Windows 应用或 COM/VSTO 加载项的升级) 中包含 Web 加载项。 (仅 Excel、PowerPoint 和 Word 加载项支持此安装选项。) 执行此作的过程取决于你是否是认证Microsoft 365 开发人员。 有关详细信息,请参阅 Microsoft 365 应用合规性计划和Microsoft 365 应用合规性计划概述。
基本步骤如下:
加入认证计划 (推荐)
建议加入 开发人员认证计划。 除此之外,这使安装程序能够更流畅地运行。 有关详细信息,请参阅以下文章:
- Microsoft 365、Teams、SaaS 和 SharePoint 应用的合作伙伴中心入门
- Microsoft 365 应用合规性
- Microsoft 365 应用合规性计划概述
- Microsoft 365 认证示例证据指南概述
更新所需的安装可执行文件 ()
下面是更新安装可执行文件的步骤。
检查用户的 Office 版本是否支持建议) (Web 加载项
建议安装检查用户是否安装了 Office 应用程序 (Excel、PowerPoint 或 Word) ,以及 Office 应用程序是否是支持在 Windows 应用程序安装中包含 Web 加载项的内部版本。 如果它是不支持 Web 加载项的旧版本,则安装程序应跳过所有剩余步骤。 请考虑向用户显示一条消息,建议他们安装或更新到最新版本的 Microsoft 365,以便他们可以利用你的 Web 加载项。 安装或升级后,他们需要重新运行安装。
所需的确切代码取决于安装框架和所使用的编程语言。 下面是如何使用 C# 检查的示例。
注意
如果计算机的管理员正在运行安装程序,则安装可以设计为计算机的所有用户安装加载项。 若要实现该设计,请更新代码以执行以下作。
检查用户是否是计算机的管理员。
如果用户是管理员,则代码应执行以下作之一。
- 如果要强制为所有用户安装加载项,代码应将
supportLocalComputer
变量设置为true
。 - 如果要让管理员选择仅为自己安装加载项还是为计算机上的所有用户安装加载项,则代码应向管理员显示一个对话框,返回管理员的选择,并相应地设置
supportLocalComputer
变量。
- 如果要强制为所有用户安装加载项,代码应将
using Microsoft.Win32;
using System;
namespace SampleProject
{
internal class IsBuildSupportedSample
{
/// <summary>
/// This function checks if the build of the Office application supports web add-ins.
/// </summary>
/// <returns> Returns true if the supported build is installed, and false if an old, unsupported build is installed or if the app is not installed at all.</returns>
private bool IsBuildSupported()
{
RegistryKey hklm = Registry.CurrentUser;
string basePath = @"Software\Microsoft\Office";
RegistryKey baseKey = Registry.CurrentUser.OpenSubKey(basePath);
string wxpName = "Word"; // Can be one of "Word", "Powerpoint", or "Excel".
bool supportLocalComputer = false; // True means LOCAL_MACHINE support, false means CURRENT_USER support.
const string buildNumberStr = "BuildNumber";
const int smallBuildNumber = 18227; // This is the minimum build that supports installation of a web add-in in the installation of a Windows app.
if (supportLocalComputer)
{
smallBuildNumber = 18730; // This is the minimum build that supports installation of a web add-in, for all users of the computer, in the installation of a Windows app.
}
const int supportedBuildMajorNumber = 16; // 16 is the lowest major build of Office applications that supports web add-ins.
if (baseKey != null)
{
Version maxVersion = new Version(supportedBuildMajorNumber, 0); // Initial value for the max supported build version
foreach (string subKeyName in baseKey.GetSubKeyNames())
{
if (Version.TryParse(subKeyName, out Version version))
{
if (version > maxVersion)
{
maxVersion = version;
}
}
}
string maxVersionString = maxVersion.ToString();
// The Office application's build number is under this path.
RegistryKey buildNumberKey = hklm.OpenSubKey(String.Format(@"Software\Microsoft\\Office\{0}\\Common\Experiment\{1}", maxVersionString, wxpName));
if (maxVersion.Major >= supportedBuildMajorNumber && buildNumberKey != null)
{
object buildNumberValue = buildNumberKey.GetValue(buildNumberStr);
if (buildNumberValue != null && Version.TryParse(buildNumberValue.ToString(), out Version version))
{
if (version.Major > supportedBuildMajorNumber || (version.Major == supportedBuildMajorNumber && version.Build >= smallBuildNumber))
{
// Build is supported
return true;
}
else
{
// Office is installed, but the build is not supported.
return false;
}
}
else
{
// There is no build number, which is an abnormal case.
return false;
}
}
else
{
// An old version is installed.
return false;
}
}
else
{
// Office is not installed.
return false;
}
}
}
}
检查 appSource 禁用 (建议)
建议安装检查用户的 Office 应用程序中是否禁用 AppSource 存储。 Microsoft 365 管理员有时会禁用存储区。 如果存储被禁用,安装程序应跳过所有剩余的步骤。 请考虑向用户显示一条消息,建议他们就 Web 加载项与其管理员联系。 启用存储后,他们需要重新运行安装。
下面是如何检查以禁用存储的示例。
using Microsoft.Win32;
using System;
namespace SampleProject
{
internal class IsStoreEnabledSample
{
/// <summary>
/// This function checks if the store is enabled.
/// </summary>
/// <returns> Returns true if it store is enabled, false if store is disabled.</returns>
private bool IsStoreEnabled()
{
RegistryKey hklm = Registry.CurrentUser;
string basePath = @"Software\Microsoft\Office";
RegistryKey baseKey = Registry.CurrentUser.OpenSubKey(basePath);
const int supportedBuildMajorNumber = 16;
if (baseKey != null)
{
Version maxVersion = new Version(supportedBuildMajorNumber, 0); // Initial value for the maximum supported build version.
foreach (string subKeyName in baseKey.GetSubKeyNames())
{
if (Version.TryParse(subKeyName, out Version version))
{
if (version > maxVersion)
{
maxVersion = version;
}
}
}
string maxVersionString = maxVersion.ToString();
// The StoreDisabled value is under this registry path.
string antoInstallPath = String.Format(@"Software\Microsoft\Office\{0}\Wef\AutoInstallAddins", maxVersionString);
RegistryKey autoInstallPathKey = Registry.CurrentUser.OpenSubKey(autoInstallPath);
if (autoInstallPathKey != null)
{
object storedisableValue = autoInstallPathKey.GetValue("StoreDisabled");
if (storedisableValue != null)
{
int value = (int)storedisableValue;
if (value == 1)
{
// Store is disabled
return false;
}
else
{
// Store is enabled
return true;
}
}
else
{
// No such key exists since the build does not have the value, so the store is enabled.
return true;
}
}
else
{
// The registry path does not exist, so the store is enabled.
return true;
}
}
else
{
// Office is not installed at all.
return false;
}
}
}
}
为外接程序创建注册表项 (所需的)
在安装程序中包括一个函数,用于将以下键和值 之一 添加到 Windows 注册表,具体取决于加载项是为计算机的所有用户安装的,还是仅针对运行安装程序的用户安装。
// Only the current user.
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Wef\AutoInstallAddins\{{OfficeApplication}}\{{add-inName}}]
"AssetIds"="{{assetId}}"
// All users of the computer.
[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\AutoInstallAddins\{{OfficeApplication}}\{{add-inName}}]
"AssetIds"="{{assetId}}"
按如下所示替换占位符:
{{OfficeApplication}}
替换为加载项应安装到的 Office 应用程序的名称。 仅Word
支持 、Excel
和PowerPoint
。注意
如果外接程序清单配置为支持多个 Office 应用程序,请将 替换为
{{OfficeApplication}}
任 一 受支持的应用程序。 不要为每个受支持的应用程序创建单独的注册表项。 将为它支持的所有 Office 应用程序安装加载项。{{add-inName}}
替换为加载项的名称;例如ContosoAdd-in
。{{assetId}}
替换为加载项的 AppSource 资产 ID,例如WA999999999
。
示例如下。
// Only the current user.
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Wef\AutoInstallAddins\Word\ContosoAdd-in]
"AssetIds"="WA999999999"
// All users of the computer.
[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\AutoInstallAddins\Word\ContosoAdd-in]
"AssetIds"="WA999999999"
确切的代码取决于安装框架和编程语言。 下面是 C# 中的一个示例。
注意
若要为所有用户安装加载项,请更改此代码, WriteRegisterKeys
使其采用 参数 bool
。 方法应将 supportLocalMachine
变量设置为传递的值: true
为所有用户安装, false
为仅为当前用户安装。
using Microsoft.Win32;
using System;
namespace SampleProject
{
internal class WriteRegisterKeysSample
{
/// <summary>
/// This function writes information to the registry that will tell Office applications to install the web add-in.
/// </summary>
private void WriteRegisterKeys()
{
bool supportLocalMachine = false; // false = CurrentUser, true = LocalMachine
RegistryKey targetRootKey = supportLocalMachine ? Registry.LocalMachine : Registry.CurrentUser;
string basePath = @"Software\Microsoft\Office";
using (RegistryKey baseKey = targetRootKey.OpenSubKey(basePath))
{
if (baseKey == null)
{
Console.WriteLine("Base registry path not found.");
return;
}
string wxpName = "Word"; // Can be "Word", "Powerpoint", or "Excel".
string assetID = "WA999999999"; // AppSource asset ID of your web add-in.
string appName = "ContosoAddin"; // Your web add-in name.
const int supportedBuildMajorNumber = 16;
const string assetIdStr = "AssetIDs";
Version maxVersion = new Version(supportedBuildMajorNumber, 0);
foreach (string subKeyName in baseKey.GetSubKeyNames())
{
if (Version.TryParse(subKeyName, out Version version))
{
if (version > maxVersion)
{
maxVersion = version;
}
}
}
string maxVersionString = maxVersion.ToString();
string subKeyPath = supportLocalMachine
? $@"Software\Microsoft\Office\{maxVersionString}\AutoInstallAddins\{wxpName}\{appName}"
: $@"Software\Microsoft\Office\{maxVersionString}\Wef\AutoInstallAddins\{wxpName}\{appName}";
using (RegistryKey addInKey = targetRootKey.CreateSubKey(subKeyPath))
{
if (addInKey != null)
{
addInKey.SetValue(assetIdStr, assetID);
}
else
{
Console.WriteLine("Failed to create or open the registry subkey.");
}
}
}
}
}
}
(认证开发人员) 所需的条款 & 条件中包含隐私条款
如果你不是认证计划的成员,请跳过此部分,但如果 是,则需要这样做。
包含在安装程序代码中,以将以下项和值 之一 添加到 Windows 注册表,具体取决于加载项是为计算机的所有用户安装的,还是仅针对运行安装程序的用户安装。
// Only the current user.
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Wef\AutoInstallAddins\{{OfficeApplication}}\{{add-inName}}]
"HasPrivacyLink"="1"
// All users of the computer.
[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\AutoInstallAddins\{{OfficeApplication}}\{{add-inName}}]
"HasPrivacyLink"="1"
完全如上一 {{OfficeApplication}}
部分所示替换 和 {{add-inName}}
占位符。 示例如下。
// Only the current user.
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Wef\AutoInstallAddins\Word\ContosoAdd-in]
"HasPrivacyLink"="1"
// All users of the computer.
[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\AutoInstallAddins\Word\ContosoAdd-in]
"HasPrivacyLink"="1"
若要实现此功能,只需在上一部分中的代码示例中进行两个小更改即可。
const
在 方法顶部的WriteRegistryKeys
列表中,添加以下行:const string hasPrivacyLinkStr = "HasPrivacyLink"; // Indicates that your installer has a privacy link.
紧跟在 行
AddInNameKey.SetValue(assetIdStr, assetID);
下面添加以下行:// Set this value if the Privacy Consent has been shown on the main app installation program, this is required for a silent installation of the web add-in. AddInNameKey.SetValue(hasPrivacyLinkStr, 1);
用户的安装体验
当最终用户运行安装可执行文件时,他们安装 Web 加载项的体验取决于两个因素。
- 你是否是 认证Microsoft 365 开发人员。
- 用户Microsoft 365 管理员所做的安全设置。
如果你已通过认证,并且管理员已为认证开发人员的所有应用启用了自动审批,则安装可执行文件启动后,无需用户执行任何特殊作即可安装 Web 加载项。 如果你未获得认证,或者管理员尚未向认证开发人员的所有应用授予自动批准,则系统会提示用户批准将 Web 加载项包含在整体安装过程中。 安装后,用户可以在 Office web 版 以及 Windows 上的 Office 中使用 Web 加载项。
如果要将 Web 加载项的安装与 COM/VSTO 加载项相结合,则需要考虑两者之间的关系。 有关详细信息,请参阅 使 Office 外接程序与现有 COM 加载项兼容。