生成 MSIX 打包组件Generating MSIX package components

本文介绍如何使用命令行工具(不使用 Visual Studio 或 MSIX 打包工具)生成用于打包应用程序的 MSIX 打包组件。This article shows you how to generate MSIX package components for packaging your application using command line tools (without using Visual Studio or the MSIX Packaging Tool).

若要手动打包应用,需要创建包清单文件,添加打包组件,然后运行 MakeAppx.exe 命令行工具来生成 MSIX 包。To manually package your app, you need to create a package manifest file, add your package components and then run the MakeAppx.exe command line tool to generate an MSIX package.

首先准备打包First, prepare to package

查看有关在打包应用程序之前需要知道的事项部分(如果尚未查看)。If you haven't yet, review this section on what you need to know before packaging your application.

创建包清单Create a package manifest

创建文件,将其命名为 appxmanifest.xml,然后在其中添加以下 XML。Create a file, name it appxmanifest.xml, and then add this XML to it.

这是一个基本模板,其中包含包所需的元素和特性。It's a basic template that contains the elements and attributes that your package needs. 在下一部分,我们会在其中添加值。We'll add values to these in the next section.

<?xml version="1.0" encoding="utf-8"?>
<Package
    xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities">
  <Identity Name="" Version="" Publisher="" ProcessorArchitecture="" />
    <Properties>
       <DisplayName></DisplayName>
       <PublisherDisplayName></PublisherDisplayName>
             <Description></Description>
      <Logo></Logo>
    </Properties>
    <Resources>
      <Resource Language="" />
    </Resources>
      <Dependencies>
      <TargetDeviceFamily Name="Windows.Desktop" MinVersion="" MaxVersionTested="" />
      </Dependencies>
      <Capabilities>
        <rescap:Capability Name="runFullTrust"/>
      </Capabilities>
    <Applications>
      <Application Id="" Executable="" EntryPoint="Windows.FullTrustApplication">
        <uap:VisualElements DisplayName="" Description=""   Square150x150Logo=""
                   Square44x44Logo=""   BackgroundColor="" />
      </Application>
     </Applications>
  </Package>

填写文件的包级元素Fill in the package-level elements of your file

在此模板中填写用于描述包的信息。Fill in this template with information that describes your package.

标识信息Identity information

下面是一个带有特性占位符文本的示例 Identity 元素。Here's an example Identity element with placeholder text for the attributes. 可将 ProcessorArchitecture 特性设置为 x64x86You can set the ProcessorArchitecture attribute to x64 or x86.

<Identity Name="MyCompany.MySuite.MyApp"
          Version="1.0.0.0"
          Publisher="CN=MyCompany, O=MyCompany, L=MyCity, S=MyState, C=MyCountry"
                ProcessorArchitecture="x64">

备注

如果已在 Microsoft Store 中保留了应用程序名称,可以使用合作伙伴中心获取“名称”和“发布者”的值。If you've reserved your application name in the Microsoft Store, you can obtain the Name and Publisher by using Partner Center. 如果你打算将应用程序旁加载到其他系统上,只要选择的发布者名称与用于对应用进行签名的证书上的名称相匹配,就可以提供自己的名称。If you plan to sideload your application onto other systems, you can provide your own names for these as long as the publisher name that you choose matches the name on the certificate you use to sign your app.

“属性”Properties

Properties 元素包含 3 个必需的子元素。The Properties element has 3 required child elements. 下面是一个带有元素占位符文本的示例 Properties 节点。Here is an example Properties node with placeholder text for the elements. DisplayName 是在 Store 中保留的应用程序名称,用于上传到 Store 的应用。The DisplayName is the name of your application that you reserve in the Store, for apps which are uploaded to the Store.

<Properties>
  <DisplayName>MyApp</DisplayName>
  <PublisherDisplayName>MyCompany</PublisherDisplayName>
  <Logo>images\icon.png</Logo>
</Properties>

资源Resources

下面是一个示例 Resources 节点。Here is an example Resources node.

<Resources>
  <Resource Language="en-us" />
</Resources>

依赖关系Dependencies

对于要为其创建包的桌面应用,请始终将 Name 特性设置为 Windows.DesktopFor desktop apps that you create a package for, always set the Name attribute to Windows.Desktop.

<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14316.0" MaxVersionTested="10.0.15063.0" />
</Dependencies>

功能Capabilities

对于要为其创建包的桌面应用,必须添加 runFullTrust 功能。For desktop apps that you create a package for, you'll have to add the runFullTrust capability.

<Capabilities>
  <rescap:Capability Name="runFullTrust"/>
</Capabilities>

填写应用程序级元素Fill in the application-level elements

在此模板中填写用于描述应用的信息。Fill in this template with information that describes your app.

Application 元素Application element

对于要为其创建包的桌面应用,Application 元素的 EntryPoint 特性始终是 Windows.FullTrustApplicationFor desktop apps that you create a package for, the EntryPoint attribute of the Application element is always Windows.FullTrustApplication.

<Applications>
  <Application Id="MyApp"     
        Executable="MyApp.exe" EntryPoint="Windows.FullTrustApplication">
   </Application>
</Applications>

可视元素Visual elements

下面是一个示例 VisualElements 节点。Here is an example VisualElements node.

<uap:VisualElements
    BackgroundColor="#464646"
    DisplayName="My App"
    Square150x150Logo="images\icon.png"
    Square44x44Logo="images\small_icon.png"
    Description="A useful description" />

(可选)添加基于目标的未着色资产(Optional) Add Target-based unplated assets

基于目标的资源是指显示在以下位置的图标和磁贴:Windows 任务栏、任务视图、ALT+TAB、贴靠助手和“开始”磁贴的右下角。Target-based assets are for icons and tiles that appear on the Windows taskbar, task view, ALT+TAB, snap-assist, and the lower-right corner of Start tiles. 可在此处了解相关详细信息。You can read more about them here.

  1. 获取正确的 44x44 图像,然后将它们复制到包含图像的文件夹(即 Assets)。Obtain the correct 44x44 images and then copy them into the folder that contains your images (i.e., Assets).

  2. 对于每个 44x44 图像,在相同的文件夹中创建副本,并将 .targetsize 44_altform unplated 附加到文件名。For each 44x44 image, create a copy in the same folder and append .targetsize-44_altform-unplated to the file name. 你应该有每个图标的两个副本,每个都以特定方式命名。You should have two copies of each icon, each named in a specific way. 例如,完成该过程后,assets 文件夹可能包含 MYAPP_44x44.pngMYAPP_44x44.targetsize-44_altform unplated.pngFor example, after completing the process, your assets folder might contain MYAPP_44x44.png and MYAPP_44x44.targetsize-44_altform-unplated.png.

    备注

    在此示例中,MYAPP_44x44.png 是将在 MSIX 包的 Square44x44Logo 徽标特性中引用的图标。In this example, the icon named MYAPP_44x44.png is the icon that you'll reference in the Square44x44Logo logo attribute of your MSIX package.

  3. 在清单文件中,对要设为透明的每个图标设置 BackgroundColorIn the manifest file, set the BackgroundColor for every icon you are making transparent.

  4. 转到下一小节,以生成新的包资源索引文件。Continue to the next subsection to generate a new Package Resource Index file.

使用 MakePri 生成包资源索引 (PRI) 文件Generate a Package Resource Index (PRI) file using MakePri

如果已按上面所述创建了基于目标的资源,或者在创建包后修改了应用程序的任何视觉资产,则必须生成新的 PRI 文件。If you create target-based assets as described in the section above, or you modify any of the visual assets of your application after you've created the package, you'll have to generate a new PRI file.

根据 SDK 的安装路径,下面是 MakePri.exe 在 Windows 10 电脑上的位置:Based on your installation path of the SDK, this is where MakePri.exe is on your Windows 10 PC:

  • x86:C:\Program Files (x86)\Windows Kits\10\bin\<build number>\x86\makepri.exex86: C:\Program Files (x86)\Windows Kits\10\bin\<build number>\x86\makepri.exe
  • x64:C:\Program Files (x86)\Windows Kits\10\bin\<build number>\x64\makepri.exex64: C:\Program Files (x86)\Windows Kits\10\bin\<build number>\x64\makepri.exe

没有此工具的 ARM 版本。There is no ARM version of this tool.

  1. 打开命令提示符或 PowerShell 窗口。Open a Command Prompt or PowerShell window.

  2. 将目录切换到包的根文件夹,然后运行命令 <path>\makepri.exe createconfig /cf priconfig.xml /dq en-US 创建 priconfig.xml 文件。Change directory to the package's root folder, and then create a priconfig.xml file by running the command <path>\makepri.exe createconfig /cf priconfig.xml /dq en-US.

  3. 使用命令 <path>\makepri.exe new /pr <PHYSICAL_PATH_TO_FOLDER> /cf <PHYSICAL_PATH_TO_FOLDER>\priconfig.xml 创建 resources.pri 文件。Create the resources.pri file(s) by using the command <path>\makepri.exe new /pr <PHYSICAL_PATH_TO_FOLDER> /cf <PHYSICAL_PATH_TO_FOLDER>\priconfig.xml.

    例如,适用于你的应用程序的命令可能如下所示:<path>\makepri.exe new /pr c:\MYAPP /cf c:\MYAPP\priconfig.xmlFor example, the command for your application might look like this: <path>\makepri.exe new /pr c:\MYAPP /cf c:\MYAPP\priconfig.xml.

  4. 根据下一步骤中的说明打包应用程序。Package your application by using the instructions in the next step.

在打包之前测试应用程序Test your application before packaging

可以部署未打包的应用程序,并在打包或签名之前对其进行测试。You can deploy your non-packaged application and test it before packaging or signing. 为此,请在 PowerShell 窗口中运行以下 cmdlet。To do so, run the cmdlet below from a PowerShell window. 确保传入位于包的根目录中的应用程序清单文件,以及其他所有包组件:Make sure to pass in your application's manifest file located in the root of your package directory with all your other package components:

Add-AppxPackage –Register AppxManifest.xml

完成此操作后,Once this is done. 应用应会部署到系统中,可对其进行测试,以确保在打包之前一切正常。Your app should be deployed on the system and you can test it to make sure everything works before packaging. 若要更新应用的 .exe 或 .dll 文件,请将包中的现有文件替换为新文件,递增 AppxManifest.xml 中的版本号,然后再次运行上述命令。To update your app's .exe or .dll files, replace the existing files in your package with the new ones, increase the version number in AppxManifest.xml, and then run the above command again.

将组件打包到 MSIXPackage your components into an MSIX

下一步是使用 MakeAppx.exe 为应用程序生成 MSIX 包。The next step is to use MakeAppx.exe to generate an MSIX package for your application. Makeappx.exe 随附在 Windows 10 SDK 中,如果你已安装 Visual Studio,则可通过 Visual Studio 的开发人员命令提示符轻松访问它。Makeappx.exe is included with the Windows 10 SDK, and if you have Visual Studio installed, it can be easily accessed through the Developer Command Prompt for Visual Studio.

请参阅使用 MakeAppx.exe 工具创建 MSIX 包或捆绑包See Create an MSIX package or bundle with the MakeAppx.exe tool

备注

打包的应用程序始终以交互用户的身份运行,任何安装已打包应用程序的驱动器必须以 NTFS 格式化。A packaged application always runs as an interactive user, and any drive that you install your packaged application on to must be formatted to NTFS format.