使用 Visual Studio 创建应用安装程序文件Create an App Installer file with Visual Studio

从 Windows 10 版本1803和 Visual Studio 2017, 更新15.7 开始, 可以将旁加载应用配置为使用.appinstaller文件接收自动更新。Starting with Windows 10, Version 1803, and Visual Studio 2017, Update 15.7, sideloaded apps can be configured to receive automatic updates using an .appinstaller file. Visual Studio 支持启用这些更新。Visual Studio supports enabling these updates.

应用安装程序文件位置App Installer file location

.appinstaller 文件可以托管在一个共享位置,如 HTTP 终结点或 UNC 共享文件夹,并包含用于查找要安装的应用包的路径。The .appinstaller file can be hosted in a shared location like a HTTP endpoint or a UNC shared folder, and includes the path to find the app packages to be installed. 用户从共享位置安装应用并启用对新更新的定期检查。Users install the app from the shared location and enable periodic checks for new updates.

配置项目 - 以正确的 Windows 版本为目标Configure the project to target the correct Windows version

你可以在创建项目时配置 TargetPlatformMinVersion 属性,也可以稍后从项目属性中进行更改。You can either configure the TargetPlatformMinVersion property when you create the project, or change it later from the project properties.

重要

仅当TargetPlatformMinVersion为 Windows 10 版本1803或更高版本时, 才会生成应用程序安装程序文件。The app installer file is only generated when the TargetPlatformMinVersion is Windows 10, Version 1803 or greater.

创建包Create packages

若要通过旁加载分发应用, 必须创建应用包 (.appx/. .msix) 或应用捆绑包 (.appxbundle/.msixbundle), 并将其发布到共享位置。To distribute an app via sideloading, you must create an app package (.appx/.msix) or app bundle (.appxbundle/.msixbundle) and publish it in a shared location.

要执行该操作,请使用 Visual Studio 中的创建应用序包向导,并执行以下步骤。To do that, use the Create App Packages wizard in Visual Studio with the following steps.

  1. 右键单击该项目,然后依次选择 Microsoft Store -> 创建应用包Right-click the project and choose Store -> Create App Packages.

    上下文菜单,可导航到“创建应用包”

    将显示创建应用包向导。The Create App Packages wizard appears.

  2. 选择 I want to create packages for sideloading.Select I want to create packages for sideloading. 启用自动更新and Enable automatic updates

    显示的“创建程序包”对话框窗口

    只有在项目的 TargetPlatformMinVersion 设置为正确的 Windows 10 版本时,才启用启用自动更新Enable automatic updates is enabled only if the project's TargetPlatformMinVersion is set to the correct version of Windows 10.

  3. 选择和配置包对话框中可以选择支持的体系结构配置。The Select and Configure Packages dialog allows you to select the supported architecture configurations. 如果选择捆绑包,将生成一个安装程序;如果不想要捆绑包,而是希望为每个体系结构生成一个程序包,它还会为每个体系结构生成一个安装程序文件。If you select a bundle it will generate a single installer, however if you don't want a bundle and prefer one package per architecture you will also get one installer file per architecture. 如果你不确定该选择哪种体系结构,或者想了解有关各种设备使用哪种体系结构的详细信息,请参阅应用包体系结构If you're unsure which architecture(s) to choose, or want to learn more about which architectures are used by various devices, see App package architectures.

  4. 配置任何其他详细信息,例如版本编号或包输出位置。Configure any additional details, such as version numbering or the package output location.

    使用显示的程序包配置创建应用包窗口

  5. 如果在步骤 2 中选中了启用自动更新,此时会显示配置更新设置对话框。If you checked Enable automatic updates in Step 2, the Configure Update Settings dialog will appear. 在该页面中,可以指定安装 URL 和更新检查频率。Here, you can specify the Installation URL and the frequency of update checks.

    配置具有发布位置配置的更新设置窗口

  6. 当你的应用成功打包后,将出现一个对话框,显示包含你的应用包的输出文件夹位置。When your app has been successfully packaged, a dialog will display the location of the output folder containing your app package. 输出文件夹包含旁加载应用所需的所有文件,包括可用于宣传你的应用的 HTML 页面。The output folder includes all the files needed to sideload the app, including an HTML page that can be used to promote your app.

发布程序包Publish packages

要使应用程序可用,必须将生成的文件发布到指定位置:To make the application available the generated files must be published to the location specified:

发布到共享文件夹 (UNC)Publish to shared folders (UNC)

如果要通过通用命名约定 (UNC) 共享文件夹发布程序包,请将应用包输出文件夹和安装 URL(请参阅步骤 6 了解详细信息)配置为相同的路径。If you want to publish your packages over Universal Naming Convention (UNC) shared folders, configure the app package output folder and the Installation URL (see Step 6 for details) to the same path. 向导将在正确的位置生成文件,用户将从同一路径获取应用和后续更新。The wizard will generate the files in the correct location, and users will get both the app and future updates from the same path.

发布到 Web 位置 (HTTP)Publish to a web location (HTTP)

要发布到 Web 位置,需要将内容发布到 Web 服务器的访问权限,确保最终 URL 与向导中定义的安装 URL 相匹配(请参阅步骤 6 了解详细信息)。Publishing to a web location requires access to publish content to the web server, making sure the final URL matches the Installation URL defined in the wizard (see Step 6 for details). 一般情况下,使用文件传输协议 (FTP) 或 SSH 文件传输协议 (SFTP) 上传文件,但还有一些其他的发布方法,如 MSDeploy、SSH 或 Blob 存储,具体视你的 Web 提供商而定。Typically, File Transfer Protocol (FTP) or SSH File Transfer Protocol (SFTP) are used to upload the files, but there are other publishing methods like MSDeploy, SSH, or Blob storage, depending on your web provider.

要配置 Web 服务器,你必须验证用于所使用的文件类型的 MIME 类型。To configure the web server you must verify the MIME types used for the file types in use. 下面的示例为 Internet Information Services (IIS) 的 web.configThis example is of the web.config for Internet Information Services (IIS):

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".appx" mimeType="application/vns.ms-appx" />
      <mimeMap fileExtension=".appxbundle" mimeType="application/vns.ms-appx" />
      <mimeMap fileExtension=".appinstaller" mimeType="application/xml" />
    </staticContent>  
  </system.webServer>  
</configuration>