从 Azure Web 应用分发 Windows 10 应用Distribute a Windows 10 app from an Azure web app

通过应用安装程序,开发人员和 IT 专业人员可以通过在各自的内容分发网络 (CDN) 上托管应用的方式来分发 Windows 10 应用。The App Installer app allows developers and IT Pros to distribute Windows 10 apps by hosting them on their own Content Delivery Network (CDN). 这种方式适用于不希望或不需要将应用发布到 Microsoft Store,但仍希望利用 Windows 10 打包和部署平台的企业。This is useful for enterprises that don't want or need to publish their apps to the Microsoft Store, but still want to take advantage of the Windows 10 packaging and deployment platform.

本主题概述了配置 Azure Web 服务器以托管 Windows 10 应用包的步骤,以及如何使用应用安装程序应用安装应用程序包。This topic outlines the steps to configure an Azure Web Server to host Windows 10 app packages, and how to use the App Installer app to install the app packages.

在此教程中,将介绍如何设置 IIS 服务器以在本地验证 Web 应用程序能否正常托管应用包,并有效地调用和使用应用安装程序。In this tutorial, we will go over setting up an IIS server to locally verify that your web application can properly host the app packages and invoke and use App Installer app effectively. 我们还另外提供了教程,介绍如何在外部的常用云 Web 服务(Azure 和 AWS)中正确托管 Web 应用程序,以确保其满足应用安装程序的 Web 安装要求。We will also have tutorials for hosting your web applications properly on the popular cloud web services in the field (Azure and AWS) to ensure that they meets the App Installer web install requirements. 此分步教程不需要任何专家知识,很容易学习。This step-by-step tutorial doesn't require any expertise and is very easy to follow.

安装Setup

要成功学习此教程,你将需要以下内容:To successfully follow this tutorial, you will need the following:

  1. Microsoft Azure 订阅Microsoft Azure subscription
  2. Windows 10 应用包-将分发的应用包Windows 10 app package - The app package that you will distribute

可选:GitHub 上的初学者项目Optional: Starter Project on GitHub. 如果没有应用包或网页可以使用,但仍想学习如何使用此功能,这个初学者项目很有用。This is helpful if you don't an app package or web page to work with, but would still like to learn how to use this feature.

步骤 1 - 获得 Azure 订阅Step 1 - Get an Azure subscription

若要获得 Azure 订阅,请访问 Azure 帐户页面To get an Azure subscription, visit the Azure account page. 可以使用免费会员资格获得此教程。For the purposes of this tutorial, you can use a free membership.

步骤 2 - 创建 Azure Web 应用Step 2 - Create an Azure Web App

在 Azure 门户页面中,单击 + 创建资源按钮,然后选择 Web 应用In the Azure portal page, click the + Create a Resource button and then select Web App

创建 Azure 应用程序的屏幕截图

创建一个唯一的应用名称,并将其余字段保留为默认值。Create a unique App name and leave the rest of the fields as default. 单击创建完成 Web 应用创建向导。Click Create to finish the Web App creation wizard.

创建 web 应用的屏幕截图

步骤 3 - 托管应用包和网页Step 3 - Hosting the app package and the web page

创建 Web 应用之后,可从 Azure 门户上的仪表板访问该应用。Once the web app had been created, you can access it from the dashboard on the Azure portal. 在此步骤中,将使用 Azure 门户的 GUI 创建一个简单的网页。In this step, we're going to create a simple web page with the GUI of the Azure portal.

从仪表板中选择新建的 Web 应用之后,使用搜索字段查找并打开应用服务编辑器After selecting the newly created web app from the dashboard, use the search field to find and open App Service Editor.

编辑器中有一个默认的 hostingstart.html 文件。In the editor, there is a default hostingstart.html file. 在文件资源管理器面板的空白区域右键单击,并选择上传文件开始上传应用包。Right-click in the empty space of file explorer panel and select Upload Files to begin uploading your app packages.

备注

如果没有可用的应用包,可以使用 GitHub 上提供的初学者项目库中包含的应用包。You can use the app package that is part of the provided Starter Project repository on GitHub if you don't have an app package available. 该应用包签名所用的证书 (MySampleApp.cer) 也随 GitHub 上的示例提供。The certificate (MySampleApp.cer) that the package was signed with is also with the sample on GitHub. 在安装应用之前,必须在设备上安装该证书。You must have the certificate installed to your device prior to installing the app.

上载包的屏幕截图

在文件资源管理器面板的空白区域右键单击,并选择新建文件创建一个新文件。Right-click in the empty space of file explorer panel and select New Files to create a new file. 为文件命名:default.htmlName the file: default.html.

如果使用的是初学者项目中提供的应用包,请将以下 HTML 代码复制到新建的网页 default.htmlIf you're using the app package provided in the Starter Project, copy the following HTML code to the newly create web page default.html. 如果使用的是自己的应用包,请修改应用服务 URL(source= 后面的 URL)。If you're using your own app package, modify the app service URL (the URL after source=). 可以从 Azure 门户中的应用概述页面获取应用服务 URL。You can get the app service URL from your app's overview page in the Azure portal.

<html>
<head>
    <meta charset="utf-8" />
    <title> Install My Sample App</title>
</head>
<body>
    <a href="ms-appinstaller:?source=https://appinstaller-azure-demo.azurewebsites.net/MySampleApp.msixbundle"> Install My Sample App</a>
</body>
</html>

步骤 4 - 针对应用包 MIME 类型配置 Web 应用Step 4 - Configure the web app for app package MIME types

向 Web 应用添加一个名为 Web.config 的新文件。Add a new file to the web app named: Web.config. 从资源管理器打开 Web.config 文件并在其中添加下面几行。Open the Web.config file from the explorer and add the following lines.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <!--This is to allow the web server to serve resources with the appropriate file extension-->
    <staticContent>
      <mimeMap fileExtension=".appx" mimeType="application/appx" />
      <mimeMap fileExtension=".msix" mimeType="application/msix" />
      <mimeMap fileExtension=".appxbundle" mimeType="application/appxbundle" />
      <mimeMap fileExtension=".msixbundle" mimeType="application/msixbundle" />
      <mimeMap fileExtension=".appinstaller" mimeType="application/appinstaller" />
    </staticContent>
  </system.webServer>
</configuration>

步骤 5 - 运行和测试Step 5 - Run and test

若要启动你创建的网页,请在浏览器中输入步骤 3 中的 URL 并在后面附加 /default.htmlTo launch the web page that you created, use the URL from step 3 into the browser followed by /default.html.

从网页安装应用程序的屏幕截图

单击“安装我的示例应用”启动应用安装程序并安装应用包。Click "Install My Sample App" to launch App Installer and install your app package.

故障排除问题Troubleshooting Issues

应用安装程序无法安装App Installer app fails to install

如果未在设备上安装为应用包签名所用的证书,应用安装将失败。App install will fail if the certificate that the app package is signed with isn't installed on the device. 若要解决此问题,需要在安装应用之前安装该证书。To fix this, you will need to install the certificate prior to the installation of the app. 如果出于公开分发目的托管应用包,建议使用证书颁发机构的证书对应用包签名。If you are hosting an app package for public distribution, we recommended signing your app package with a certificate from a certificate authority.

认证失败的屏幕截图

确保应用安装程序已安装。Ensure that the App Installer app is installed. 转到设置 -> 应用和功能,在已安装应用列表中找到应用安装程序。Go to Settings -> Apps & Features and find App Installer in the installed apps list.