使用 Microsoft Store Services SDK 与客户互动Engage customers with the Microsoft Store Services SDK

Microsoft Store Services SDK 提供了一些功能,可帮助你与通用 Windows 平台中的客户 (UWP) 应用程序,如将目标通知发送到应用,并在应用中运行 A/B 试验。The Microsoft Store Services SDK provides features that help you engage with customers in your Universal Windows Platform (UWP) apps, such as sending targeted notifications to your apps and running A/B experiments in your apps. 此 SDK 是 Visual Studio 2015 和更高版本的 Visual Studio 的扩展。This SDK is an extension for Visual Studio 2015 and later versions of Visual Studio.

备注

要在 UWP 应用中显示广告,请使用 Microsoft 广告 SDK 而不是 Microsoft Store Services SDK。To display ads in your UWP apps, use the Microsoft Advertising SDK instead of the Microsoft Store Services SDK. 广告库已从 Microsoft Store Services SDK 移至 Microsoft 广告 SDK。The advertising libraries have been moved from the Microsoft Store Services SDK to the Microsoft Advertising SDK. 有关详细信息,请参阅在应用中显示广告For more information, see Display ads in your app.

Microsoft Store Services SDK 支持的方案Scenarios supported by the Microsoft Store Services SDK

Microsoft Store Services SDK 当前支持以下适用于 UWP 应用的方案。The Microsoft Store Services SDK currently supports the following scenarios for UWP apps. 有关 API 的参考文档,请参阅 Microsoft Store Services SDK API 参考For API reference documentation, see Microsoft Store Services SDK API reference.

方案Scenario 描述Description
在 UWP 应用中使用 A/B 测试运行实验Run experiments in your UWP app with A/B testing 在通用 Windows 平台 (UWP) 应用上运行 A/B 测试,测量这些功能对某些客户的有效性,之后再将它们发布给每位用户。Run A/B tests in your Universal Windows Platform (UWP) app to measure the effectiveness of features on some customers before you release the features to everyone. 在伙伴中心定义试验后,请使用 StoreServicesExperimentVariation 类在应用中获取试验的变体,使用此数据修改正在测试的功能的行为,然后使用 LogForVariation 方法将查看事件和转换事件发送到合作伙伴中心。After you define an experiment in Partner Center, use the StoreServicesExperimentVariation class to get variations for your experiment in your app, use this data to modify the behavior of the feature you are testing, and then use the LogForVariation method to send view event and conversion events to Partner Center. 最后,使用 "合作伙伴中心" 查看结果并管理试验。Finally, use Partner Center to view the results and manage the experiment.
从 UWP 应用启动“反馈中心”Launch Feedback Hub from your UWP app 使用 UWP 应用中的 StoreServicesFeedbackLauncher 类将 Windows 10 客户定向到“反馈中心”,他们可以在其中提交问题、建议和赞成票。Use the StoreServicesFeedbackLauncher class in your UWP app to direct your Windows 10 customers to Feedback Hub, where they can submit problems, suggestions, and upvotes. 然后,在合作伙伴中心内的反馈报告中管理此反馈。Then, manage this feedback in the Feedback report in Partner Center.
配置 UWP 应用以接收合作伙伴中心推送通知Configure your UWP app to receive Partner Center push notifications 在 UWP 应用中使用 StoreServicesEngagementManager 类来注册你的应用,以接收你使用合作伙伴中心向客户发送的目标推送通知。Use the StoreServicesEngagementManager class in your UWP app to register your app to receive targeted push notifications that you send to your customers using Partner Center.
为合作伙伴中心内的使用情况报表记录 UWP 应用中的自定义事件Log custom events in your UWP app for the Usage report in Partner Center 在 UWP 应用中使用 StoreServicesCustomEventLogger 类来记录与合作伙伴中心中的应用关联的自定义事件。Use the StoreServicesCustomEventLogger class in your UWP app to log custom events that are associated with your app in Partner Center. 然后,在 "合作伙伴中心" 中的 "使用情况报告" 的 "自定义事件" 部分中查看自定义事件的总次数。Then, review the total occurrences for your custom events in the Custom events section of the Usage report in Partner Center.

必备条件Prerequisites

Microsoft Store Services SDK 需要:The Microsoft Store Services SDK requires:

  • Visual Studio 2015 或更高版本。Visual Studio 2015 or a later version.
  • 与你的 Visual Studio 版本一起安装适用于通用 Windows 应用的 Visual Studio Tools。Visual Studio Tools for Universal Windows Apps installed with your version of Visual Studio.

安装 SDKInstall the SDK

在开发计算机上安装 Microsoft Store Services SDK 的方法有两种:There are two options for installing the Microsoft Store Services SDK on your development computer:

  • MSI 安装程序    可以通过此处提供的 MSI 安装程序安装 SDK。MSI installer  You can install the SDK via the MSI installer available here.
  • NuGet 包    可以将 SDK 安装为 NuGet 包。NuGet package  You can install the SDK as a NuGet package.

Microsoft 会定期发布带有性能改进和新功能的 Microsoft Store Services SDK 新版本。Microsoft periodically releases new versions of the Microsoft Store Services SDK with performance improvements and new features. 如果你有使用该 SDK 的现有项目,并且你希望使用最新版本,请在开发计算机上下载并安装最新版本的 SDK。If you have existing projects that use the SDK and you want to use the latest version, download and install the latest version of the SDK on your development computer.

通过 MSI 安装Install via MSI

若要通过 MSI 安装程序安装 Microsoft Store Services SDK:To install the Microsoft Store Services SDK via the MSI installer:

  1. 关闭 Visual Studio 的所有实例。Close all instances of Visual Studio.

  2. 如果之前已安装 Microsoft 官方商城协定和盈利 SDK、通用广告客户端 SDK 或 Ad Mediator 扩展,请先卸载这些 SDK。If you previously installed the Microsoft Store Engagement and Monetization SDK, Universal Ad Client SDK, or Ad Mediator extension, uninstall these SDKs now. (可选)打开命令提示符窗口并运行这些命令以清除可能与 Visual Studio 一起安装(但可能未显示在计算机上的已安装程序列表中)的任何早期 SDK 版本:Optionally, open a Command Prompt window and run these commands to clean out any older SDK versions that may have been installed with Visual Studio, but which may not appear in the list of installed programs on your computer:

    MsiExec.exe /x{5C87A4DB-31C7-465E-9356-71B485B69EC8}
    MsiExec.exe /x{6AB13C21-C3EC-46E1-8009-6FD5EBEE515B}
    MsiExec.exe /x{6AC81125-8485-463D-9352-3F35A2508C11}
    
  3. 下载并安装 Microsoft Store Services SDKDownload and install the Microsoft Store Services SDK. 安装它可能需要几分钟。It may take a few minutes to install. 请确信并等待,直到进程结束。Be sure and wait until the process has finished.

  4. 重启 Visual Studio。Restart Visual Studio.

  5. 如果你的现有项目引用任何较早版本的 Microsoft Store Services SDK、Microsoft 广告 SDK、通用广告客户端 SDK 或 Microsoft 官方商城协定和盈利 SDK 中的库,我们建议你在 Visual Studio 中打开项目,然后清除并重新生成项目(在解决方案资源管理器中,右键单击项目节点并选择清除,然后再次右键单击项目节点并选择重新生成)。If you have an existing project that references libraries from any earlier version of the Microsoft Store Services SDK, Microsoft Advertising SDK, Universal Ad Client SDK, or Microsoft Store Engagement and Monetization SDK, we recommend that you open your project in Visual Studio and clean and rebuild your project (in Solution Explorer, right-click your project node and choose Clean, and then right-click your project node again and choose Rebuild).

如果你在项目中首次使用此 SDK,则你现在可以为你的项目添加程序集引用Otherwise, if you are using the SDK for the first time in your project, you are now ready to add the assembly reference to your project.

通过 NuGet 安装Install via NuGet

若要通过 NuGet 安装 Microsoft Store Services SDK 库:To install the Microsoft Store Services SDK libraries via NuGet:

  1. 关闭 Visual Studio 的所有实例。Close all instances of Visual Studio.

  2. 如果之前已安装 Microsoft 官方商城协定和盈利 SDK、通用广告客户端 SDK 或 Ad Mediator 扩展,请先卸载这些 SDK。If you previously installed the Microsoft Store Engagement and Monetization SDK, Universal Ad Client SDK, or Ad Mediator extension, uninstall these SDKs now. (可选)打开命令提示符窗口并运行这些命令以清除可能与 Visual Studio 一起安装(但可能未显示在计算机上的已安装程序列表中)的任何早期 SDK 版本:Optionally, open a Command Prompt window and run these commands to clean out any older SDK versions that may have been installed with Visual Studio, but which may not appear in the list of installed programs on your computer:

    MsiExec.exe /x{5C87A4DB-31C7-465E-9356-71B485B69EC8}
    MsiExec.exe /x{6AB13C21-C3EC-46E1-8009-6FD5EBEE515B}
    MsiExec.exe /x{6AC81125-8485-463D-9352-3F35A2508C11}
    
  3. 启动 Visual Studio 并打开要使用 Microsoft Store Services SDK 的项目。Start Visual Studio and open the project in which you want to use the Microsoft Store Services SDK.

    备注

    如果项目已经包含来自 SDK 的较早 MSI 安装的库引用,请从项目中删除这些引用。If your project already includes library references from an earlier MSI installation of the SDK, remove these references from your project. 这些引用的旁边将出现警告图标,因为它们引用的库已在之前的步骤中删除。These references will have warning icons next to them because the libraries they reference were removed in the previous steps.

  4. 在 Visual Studio 中,依次单击项目管理 NuGet 包In Visual Studio, click Project and Manage NuGet Packages.

  5. 在搜索框中,键入 Microsoft.Services.Store.Engagement 并安装 Microsoft.Services.Store.Engagement 包。In the search box, type Microsoft.Services.Store.Engagement and install the Microsoft.Services.Store.Engagement package. 程序包安装完成后,保存你的解决方案。When the package is done installing, save your solution.

    备注

    如果输出窗口报告指示指定路径过长的 Install-Package 错误,则可能需要配置 NuGet 以将软件包提取到路径短于默认位置的备用位置。If the Output window reports an Install-Package error that indicates the specified path is too long, you may need to configure NuGet to extract packages to an alternate location with a shorter path than the default location. 若要执行此操作,将 repositoryPath 值添加到计算机上的 nuget.config 文件,并将其分配到可从中提取 NuGet 包的短文件夹路径。To do this, add the repositoryPath value to a nuget.config file on your computer and assign it to a short folder path where NuGet packages can be extracted. 有关详细信息,请参阅 NuGet 文档中的此文章For more information, see this article in the NuGet documentation. 或者,可尝试将 Visual Studio 项目移到路径较短的备用文件夹。Alternatively, you can try moving your Visual Studio project to an alternate folder with a shorter path. 此问题也可能是由于全局包路径过长造成的。The problem could also be caused by your global packages path being too long. 在这种情况下,将 globalPackagesFolder 值添加到 nuget.config 文件中。In this case, add the globalPackagesFolder value into your nuget.config file.

  6. 关闭包含你的项目的 Visual Studio 解决方案,然后重新打开解决方案。Close the Visual Studio solution that contains your project and then reopen the solution.

  7. 如果你的项目已从通过 NuGet 安装的 Microsoft Store Services SDK 的早期版本引用库,并且你已将项目更新为较新版本的 SDK,则建议你清除并重新生成项目 (在 解决方案资源管理器中,右键单击项目节点并选择 " 清理",然后再次右键单击项目节点,然后选择 " 重新生成) "。If your project already references libraries from an earlier version of the Microsoft Store Services SDK that was installed via NuGet and you have updated your project to a newer release of the SDK, we recommend that you clean and rebuild your project (in Solution Explorer, right-click your project node and choose Clean, and then right-click your project node again and choose Rebuild).

如果你在项目中首次使用此 SDK,则你现在可以为你的项目添加程序集引用Otherwise, if you are using the SDK for the first time in your project, you are now ready to add the assembly reference to your project.

为你的项目添加程序集应用Add the assembly reference to your project

通过 MSI 安装程序或 NuGet 安装 Microsoft Store Services SDK 后,请按照以下说明在 UWP 项目中引用 SDK 程序集。After you install the Microsoft Store Services SDK via the MSI installer or NuGet, follow these instructions to reference the SDK assembly in your UWP project.

  1. 在 Visual Studio 中打开项目。Open your project in Visual Studio.

    备注

    如果项目是面向任何 CPU的 JavaScript 应用,请更新项目以使用特定于体系结构的生成输出(例如,x86)。If your project is a JavaScript app that targets Any CPU, update your project to use an architecture-specific build output (for example, x86).

  2. 解决方案资源管理器中,右键单击 "引用",然后选择 "添加引用 ... "In Solution Explorer, right click References and select Add Reference…

  3. 引用管理器中,展开通用 Windows、单击扩展,然后选中 Microsoft 协议框架旁边的复选框。In Reference Manager, expand Universal Windows, click Extensions, and then select the check box next to Microsoft Engagement Framework. 这使你能够使用 Microsoft.Services.Store.Engagement 命名空间中的 API。This enables you to use the APIs in the Microsoft.Services.Store.Engagement namespace.

  4. 单击" 确定"。Click OK.

备注

如果你已通过 NuGet 安装了 SDK 库,则你的项目将包含 Microsoft.Services.Store.Engagement 引用。If you installed the SDK libraries via NuGet, your project will contain a Microsoft.Services.Store.Engagement reference. Microsoft.Services.Store.Engagement 引用表示 NuGet 包(而不是其中的库),因此,你可以将其忽略。The Microsoft.Services.Store.Engagement reference represents the NuGet package (rather than the libraries in it), and you can ignore it.

了解 SDK 中的框架包Understanding framework packages in the SDK

Microsoft Store Services SDK 中的 Microsoft.Services.Store.Engagement.dll 库配置为框架包The Microsoft.Services.Store.Engagement.dll library in the Microsoft Store Services SDK is configured as a framework package. 此库包含 Microsoft.Services.Store.Engagement 命名空间中的 API。This library contains the APIs in the Microsoft.Services.Store.Engagement namespace.

此库是一个框架包,因此,这意味着在用户安装使用此库的应用版本之后,无论我们何时发布新版本的库及修复和性能增强,Windows 更新均会在其设备上自动更新此库。Because this library is a framework package, this means that after a user installs a version of your app that uses this library, this library is automatically updated on their device through Windows Update whenever we publish a new version of the library with fixes and performance improvements. 这有助于确保客户始终在其设备上安装最新可用版本的库。This helps to ensure that your customers always have the latest available version of the library installed on their devices.

如果我们发布的新版本 SDK 引入了此库中新的 API 或功能,你将需要安装最新版本的 SDK 才能使用这些功能。If we release a new version of the SDK that introduces new APIs or features in this library, you will need to install the latest version of the SDK to use those features. 在本方案中,你还需要将更新的应用发布到应用商店。In this scenario, you would also need to publish your updated app to the Store.