Skip to main content

Windows Store GuideWindows应用商店指南

With Windows 10, the good old win32 executable got a new sibling: The Universal Windows Platform. 在Windows10中,优秀的旧win32可执行文件有了一个新的兄弟:通用Windows平台。The new .appx format does not only enable a number of new powerful APIs like Cortana or Push Notifications, but through the Windows Store, also simplifies installation and updating.新的.appx格式不仅支持许多新的强大API,如Cortana或推送通知,而且通过Windows应用商店,还简化了安装和更新。

Microsoft developed a tool that compiles Electron apps as .appx packages, enabling developers to use some of the goodies found in the new application model. 微软开发了一种将Electron应用程序编译为.appx包的工具,使开发人员能够使用新应用程序模型中的一些优点。This guide explains how to use it - and what the capabilities and limitations of an Electron AppX package are.本指南解释了如何使用它,以及Electron AppX软件包的功能和限制是什么。

Background and Requirements背景和要求

Windows 10 "Anniversary Update" is able to run win32 .exe binaries by launching them together with a virtualized filesystem and registry. Windows 10“Anniversary Update”可以运行win32 .exe二进制文件,方法是将它们与虚拟文件系统和注册表一起启动。Both are created during compilation by running app and installer inside a Windows Container, allowing Windows to identify exactly which modifications to the operating system are done during installation. 两者都是在编译过程中通过在Windows容器中运行应用程序和安装程序创建的,允许Windows准确识别在安装过程中对操作系统进行的修改。Pairing the executable with a virtual filesystem and a virtual registry allows Windows to enable one-click installation and uninstallation.通过将可执行文件与虚拟文件系统和虚拟注册表配对,Windows可以实现一键式安装和卸载。

In addition, the exe is launched inside the appx model - meaning that it can use many of the APIs available to the Universal Windows Platform. 此外,exe是在appx模型内启动的,这意味着它可以使用Universal Windows Platform可用的许多API。To gain even more capabilities, an Electron app can pair up with an invisible UWP background task launched together with the exe - sort of launched as a sidekick to run tasks in the background, receive push notifications, or to communicate with other UWP applications.为了获得更多功能,Electron应用程序可以与一个不可见的UWP后台任务配对,该任务与.exe一起启动,可以作为助手在后台运行任务、接收推送通知或与其他UWP应用程序通信。

To compile any existing Electron app, ensure that you have the following requirements:要编译任何现有Electron应用程序,请确保您具有以下要求:

  • Windows 10 with Anniversary Update (released August 2nd, 2016)带有周年更新的Windows 10(2016年8月2日发布)
  • The Windows 10 SDK, downloadable hereWindows 10 SDK,可在此处下载
  • At least Node 4 (to check, run node -v)至少节点4(要进行检查,请运行node -v

Then, go and install the electron-windows-store CLI:然后,转到并安装electron-windows-storeCLI:

npm install -g electron-windows-store

Step 1: Package Your Electron Application打包Electron应用程序

Package the application using electron-packager (or a similar tool). 使用Electron打包器(或类似工具)打包应用程序。Make sure to remove node_modules that you don't need in your final application, since any module you don't actually need will increase your application's size.确保删除最终应用程序中不需要的node_modules,因为实际上不需要的任何模块都会增加应用程序的大小。

The output should look roughly like this:输出大致如下:

├── Ghost.exe
├── LICENSE
├── content_resources_200_percent.pak
├── content_shell.pak
├── d3dcompiler_47.dll
├── ffmpeg.dll
├── icudtl.dat
├── libEGL.dll
├── libGLESv2.dll
├── locales
│   ├── am.pak
│   ├── ar.pak
│   ├── [...]
├── node.dll
├── resources
│   └── app.asar
├── v8_context_snapshot.bin
├── squirrel.exe
└── ui_resources_200_percent.pak

Step 2: Running electron-windows-store运行electron-windows-store

From an elevated PowerShell (run it "as Administrator"), run electron-windows-store with the required parameters, passing both the input and output directories, the app's name and version, and confirmation that node_modules should be flattened.从提升的PowerShell(以“管理员”身份运行),使用所需参数运行electron-windows-store,传递输入和输出目录、应用程序的名称和版本,并确认node_modules应被展平。

electron-windows-store `
--input-directory C:\myelectronapp `
--output-directory C:\output\myelectronapp `
--package-version 1.0.0.0 `
--package-name myelectronapp

Once executed, the tool goes to work: It accepts your Electron app as an input, flattening the node_modules. 执行后,该工具开始工作:它接受Electron应用程序作为输入,使node_modules变平。Then, it archives your application as app.zip. 然后,它将应用程序归档为app.zipUsing an installer and a Windows Container, the tool creates an "expanded" AppX package - including the Windows Application Manifest (AppXManifest.xml) as well as the virtual file system and the virtual registry inside your output folder.该工具使用安装程序和Windows容器创建“扩展”的AppX包,其中包括Windows应用程序清单(AppXManifest.xml)以及输出文件夹中的虚拟文件系统和虚拟注册表。

Once the expanded AppX files are created, the tool uses the Windows App Packager (MakeAppx.exe) to create a single-file AppX package from those files on disk. 创建扩展的AppX文件后,该工具将使用Windows App Packager(MakeAppx.exe)从磁盘上的这些文件创建单个文件AppX包。Finally, the tool can be used to create a trusted certificate on your computer to sign the new AppX package. 最后,该工具可用于在计算机上创建可信证书,以签署新的AppX包。With the signed AppX package, the CLI can also automatically install the package on your machine.使用签名的AppX软件包,CLI还可以在您的计算机上自动安装该软件包。

Step 3: Using the AppX Package使用AppX包

In order to run your package, your users will need Windows 10 with the so-called "Anniversary Update" - details on how to update Windows can be found here.为了运行您的软件包,您的用户将需要具有所谓“周年更新”的Windows 10,有关如何更新Windows的详细信息,请参阅此处

In opposition to traditional UWP apps, packaged apps currently need to undergo a manual verification process, for which you can apply here. 与传统的UWP应用程序相反,打包的应用程序目前需要进行手动验证过程,您可以在这里申请。In the meantime, all users will be able to install your package by double-clicking it, so a submission to the store might not be necessary if you're looking for an easier installation method. 同时,所有用户都可以通过双击来安装您的软件包,因此,如果您正在寻找更简单的安装方法,则可能不需要提交到存储区。In managed environments (usually enterprises), the Add-AppxPackage PowerShell Cmdlet can be used to install it in an automated fashion.在托管环境(通常是企业)中,可以使用Add-AppxPackage PowerShell Cmdlet自动安装它

Another important limitation is that the compiled AppX package still contains a win32 executable - and will therefore not run on Xbox, HoloLens, or Phones.另一个重要的限制是编译的AppX包仍然包含一个win32可执行文件,因此不能在Xbox、HoloLens或Phones上运行。

Optional: Add UWP Features using a BackgroundTask可选:使用BackgroundTask添加UWP功能

You can pair your Electron app up with an invisible UWP background task that gets to make full use of Windows 10 features - like push notifications, Cortana integration, or live tiles.您可以将Electron应用程序与一个隐形UWP后台任务配对,以充分利用Windows 10的功能,如推送通知、Cortana集成或实时瓷砖。

To check out how an Electron app that uses a background task to send toast notifications and live tiles, check out the Microsoft-provided sample.要查看使用后台任务发送toast通知和实时互动程序的Electron应用程序,请查看Microsoft提供的示例

Optional: Convert using Container Virtualization可选:使用容器虚拟化进行转换

To generate the AppX package, the electron-windows-store CLI uses a template that should work for most Electron apps. 为了生成AppX包,electron-windows-storeCLI使用了一个适用于大多数electron应用程序的模板。However, if you are using a custom installer, or should you experience any trouble with the generated package, you can attempt to create a package using compilation with a Windows Container - in that mode, the CLI will install and run your application in blank Windows Container to determine what modifications your application is exactly doing to the operating system.但是,如果您正在使用自定义安装程序,或者如果生成的程序包出现任何问题,您可以尝试使用Windows容器编译来创建程序包-在该模式下,CLI将在空白Windows容器中安装并运行应用程序,以确定应用程序对操作系统的确切修改。

Before running the CLI for the first time, you will have to setup the "Windows Desktop App Converter". 首次运行CLI之前,必须设置“Windows桌面应用程序转换器”。This will take a few minutes, but don't worry - you only have to do this once. 这需要几分钟的时间,但别担心,你只需要做一次。Download and Desktop App Converter from here. 此处下载和桌面应用程序转换器。You will receive two files: DesktopAppConverter.zip and BaseImage-14316.wim.您将收到两个文件:DesktopAppConverter.zipBaseImage-14316.wim

  1. Unzip DesktopAppConverter.zip. 解压缩DesktopAppConverter.zipFrom an elevated PowerShell (opened with "run as Administrator", ensure that your systems execution policy allows us to run everything we intend to run by calling Set-ExecutionPolicy bypass.从提升的PowerShell(以“以管理员身份运行”打开)中,确保您的系统执行策略允许我们通过调用Set-ExecutionPolicy bypass来运行我们想要运行的所有内容。
  2. Then, run the installation of the Desktop App Converter, passing in the location of the Windows base Image (downloaded as BaseImage-14316.wim), by calling .\DesktopAppConverter.ps1 -Setup -BaseImage .\BaseImage-14316.wim.然后,运行桌面应用程序转换器的安装,通过调用.\DesktopAppConverter.ps1 -Setup -BaseImage .\BaseImage-14316.wim传入Windows基本映像(下载为BaseImage-14316.wim)的位置。
  3. If running the above command prompts you for a reboot, please restart your machine and run the above command again after a successful restart.如果运行上述命令提示您重新启动,请重新启动计算机,并在成功重新启动后再次运行上述命令。

Once installation succeeded, you can move on to compiling your Electron app.安装成功后,您可以继续编译Electron应用程序。