使用 MakeAppx.exe 创建 .MSIX 包或捆绑包Create an MSIX package or bundle with MakeAppx.exe

MakeAppx.exe 将 ( .msix 或 .appx) 和应用包 ( 捆绑包) 中创建应用包。MakeAppx.exe creates both app packages (.msix or .appx) and app package bundles (.msixbundle or .appxbundle). MakeAppx.exe 还从应用包或捆绑包中提取文件,并加密或解密应用程序包和捆绑包。MakeAppx.exe also extracts files from an app package or bundle and encrypts or decrypts app packages and bundles. 此工具包含在 Windows 10 SDK 中,并且可以从命令提示符或脚本文件中使用。This tool is included in the Windows 10 SDK and can be used from a command prompt or a script file.

有关如何使用 MakeApp.exe 打包桌面应用程序的信息,请参阅 手动打包桌面应用程序For information about how to use MakeApp.exe to package a desktop app, see Package a desktop app manually.

重要

如果你使用 Visual Studio 开发你的应用,建议使用 Visual Studio 向导创建应用包。If you used Visual Studio to develop your app, it's recommended that you use the Visual Studio wizard to create your app package. 有关详细信息,请参阅使用 Visual Studio 打包 UWP 应用使用 visual Studio 从源代码打包桌面应用For more information, see Package a UWP app with Visual Studio and Package a desktop app from source code using Visual Studio.

重要

请注意, MakeAppx.exe 不会创建 应用包上传文件 ( .appxupload 或 msixupload) ,这是用于 提交到合作伙伴中心的有效应用包的建议类型。Note that MakeAppx.exe does not create an app package upload file (.appxupload or .msixupload), which is the recommended type of valid app package for submissions to Partner Center. 应用包上传文件通常 作为 Visual Studio 打包过程的一部分创建,但也可以手动创建。The app package upload file is typically created as part of the Visual Studio packaging process, although it can also be created manually.

使用 MakeAppx.exeUsing MakeAppx.exe

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

  • x86: C:\Program Files (x86) \Windows Kits\10\bin arch> \ < 内部版本号 >\x86\makeappx.exex86: C:\Program Files (x86)\Windows Kits\10\bin\<build number>\x86\makeappx.exe
  • x64: C:\Program Files (x86) \Windows Kits\10\bin arch> \ < 内部版本号 >\x64\makeappx.exex64: C:\Program Files (x86)\Windows Kits\10\bin\<build number>\x64\makeappx.exe

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

MakeAppx.exe 语法和选项MakeAppx.exe syntax and options

常规 MakeAppx.exe 语法:General MakeAppx.exe syntax:

MakeAppx <command> [options]      

下表介绍了 MakeAppx.exe 的命令。The following table describes the commands for MakeAppx.exe.

命令Command 说明Description
packpack 创建程序包。Creates a package.
unpackunpack 将指定程序包中的所有文件提取到指定的输出目录。Extracts all files in the specified package to the specified output directory.
bundlebundle 创建捆绑包。Creates a bundle.
unbundleunbundle 将所有程序包解压到以捆绑包完整名称命名的指定输出路径下的子目录中。Unpacks all packages to a subdirectory under the specified output path named after the bundle full name.
encryptencrypt 在指定的输出程序包/捆绑包中,从输入程序包/捆绑包中创建加密的应用包或捆绑包。Creates an encrypted app package or bundle from the input package/bundle at the specified output package/bundle.
解密decrypt 在指定的输出程序包/捆绑包中,从输入应用包/捆绑包中创建解密的应用包或捆绑包。Creates an decrypted app package or bundle from the input app package/bundle at the specified output package/bundle.

此选项列表适用于所有命令:This list of options applies to all commands:

选项Option 说明Description
/d/d 指定输入、输出或内容目录。Specifies the input, output, or content directory.
/l/l 用于本地化的程序包。Used for localized packages. 本地化程序包上的默认验证过程。The default validation trips on localized packages. 此选项仅禁用特定验证,无需禁用所有验证。This options disables only that specific validation, without requiring that all validation be disabled.
/kf/kf 使用指定密钥文件中的键加密或解密程序包或捆绑包。Encrypts or decrypts the package or bundle using the key from the specified key file. 它不能与 /kt 一起使用。This can't be used with /kt.
/kt/kt 使用全局测试密钥加密或解密程序包或捆绑包。Encrypts the or decrypts package or bundle using the global test key. 它不能与 /kf 一起使用。This can't be used with /kf.
/no/no 如果存在,会阻止输出文件的覆盖。Prevents an overwrite of the output file if it exists. 如果不指定此选项或 /o 选项,将询问用户是否要覆盖文件。If you don't specify this option or the /o option, the user is asked whether they want to overwrite the file.
/nv/nv 跳过语义验证。Skips semantic validation. 如果不指定此选项,该工具将执行程序包的完整验证。If you don't specify this option, the tool performs a full validation of the package.
/o/o 覆盖输出文件(如果存在)。Overwrites the output file if it exists. 如果不指定此选项或 /no 选项,将询问用户是否要覆盖文件。If you don't specify this option or the /no option, the user is asked whether they want to overwrite the file.
/p/p 指定应用包或捆绑包。Specifies the app package or bundle.
/v/v 使详细日志记录输出到控制台。Enables verbose logging output to the console.
/?/? 显示帮助文本。Displays help text.

下面的列表包含可能的参数:The following list contains possible arguments:

ArgumentArgument 说明Description
<output package name><output package name> 创建的程序包的名称。The name of the package created. 这是 .msix 或 .appx 后面追加的文件名。This is the file name appended with .msix or .appx.
<encrypted output package name><encrypted output package name> 创建的加密包的名称。The name of the encrypted package created. 这是追加了. emsix 或. eappx 的文件名。This is the file name appended with .emsix or .eappx.
<input package name><input package name> 包的名称。The name of the package. 这是 .msix 或 .appx 后面追加的文件名。This is the file name appended with .msix or .appx.
<encrypted input package name><encrypted input package name> 加密包的名称。The name of the encrypted package. 这是追加了. emsix 或. eappx 的文件名。This is the file name appended with .emsix or .eappx.
<output bundle name><output bundle name> 创建的捆绑包的名称。The name of the bundle created. 这是 .msixbundle 或 .appxbundle 后面追加的文件名。This is the file name appended with .msixbundle or .appxbundle.
<encrypted output bundle name><encrypted output bundle name> 创建的加密捆绑包的名称。The name of the encrypted bundle created. 这是追加了. emsixbundle 或. eappxbundle 的文件名。This is the file name appended with .emsixbundle or .eappxbundle.
<input bundle name><input bundle name> 捆绑包的名称。The name of the bundle. 这是 .msixbundle 或 .appxbundle 后面追加的文件名。This is the file name appended with .msixbundle or .appxbundle.
<encrypted input bundle name><encrypted input bundle name> 加密捆绑包的名称。The name of the encrypted bundle. 这是追加了. emsixbundle 或. eappxbundle 的文件名。This is the file name appended with .emsixbundle or .eappxbundle.
<content directory><content directory> 应用包或捆绑包内容的路径。Path for the app package or bundle content.
<mapping file><mapping file> 指定程序包源和目标的文件名。File name that specifies the package source and destination.
<output directory><output directory> 输出程序包和捆绑包的目录路径。Path to the directory for output packages and bundles.
<密钥文件><key file> 含有加密或解密的密钥的文件名。Name of the file containing a key for encryption or decryption.
<algorithm ID><algorithm ID> 创建块映射时使用的算法。Algorithms used when creating a block map. 有效算法包括:SHA256(默认值)、SHA384、SHA512。Valid algorithms include: SHA256 (default), SHA384, SHA512.

创建应用程序包Create an app package

应用包是打包到 .msix 或 .appx 包文件中的应用文件的完整集。An app package is a complete set of the app's files packaged in to a .msix or .appx package file. 若要使用 pack 命令创建应用包,必须提供程序包位置的内容目录或映射文件。To create an app package using the pack command, you must provide either a content directory or a mapping file for the location of the package. 你还可以在创建它时加密程序包。You can also encrypt a package while creating it. 如果你想要加密程序包,必须使用 /ep 并指定是否使用密钥文件 (/kf) 或全局测试密钥 (/kt)。If you want to encrypt the package, you must use /ep and specify if you are using a key file (/kf) or the global test key (/kt). 有关创建加密程序包的详细信息,请参阅加密或解密程序包或捆绑包For more information on creating an encrypted package, see Encrypt or decrypt a package or bundle.

特定于 pack 命令的选项:Options specific to the pack command:

选项Option 说明Description
/f/f 指定映射文件。Specifies the mapping file.
/h/h 指定创建块映射时使用的哈希算法。Specifies the hash algorithm to use when creating the block map. 它仅可以与 pack 命令一起使用。This can only be used with the pack command. 有效算法包括:SHA256(默认值)、SHA384、SHA512。Valid algorithms include: SHA256 (default), SHA384, SHA512.
/m/m 指定输入应用清单的路径,该清单将用于生成输出应用包或资源包清单的基础。Specifies the path to an input app manifest which will be used as the basis for generating the output app package or resource package's manifest. 当使用此选项时,还必须使用 /f 并在映射文件中包含 [ResourceMetadata] 部分,来指定要包含在生成的清单中的资源维度。When you use this option, you must also use /f and include a [ResourceMetadata] section in the mapping file to specify the resource dimensions to be included in the generated manifest.
/nc/nc 阻止程序包文件的压缩。Prevents compression of the package files. 默认情况下,将基于检测到的文件类型压缩文件。By default, files are compressed based on detected file type.
/r/r 生成资源包。Builds a resource package. 它必须与 /m 一起使用,并表示使用 /l 选项。This must be used with /m and implies the use of the /l option.

下面的用法示例演示了一些可能的 pack 命令语法选项:The following usage examples show some possible syntax options for the pack command:

MakeAppx pack [options] /d <content directory> /p <output package name>
MakeAppx pack [options] /f <mapping file> /p <output package name>
MakeAppx pack [options] /m <app package manifest> /f <mapping file> /p <output package name>
MakeAppx pack [options] /r /m <app package manifest> /f <mapping file> /p <output package name>
MakeAppx pack [options] /d <content directory> /ep <encrypted output package name> /kf <key file>
MakeAppx pack [options] /d <content directory> /ep <encrypted output package name> /kt

下面显示了 pack 命令的命令行示例:The following shows command line examples for the pack command:

MakeAppx pack /v /h SHA256 /d "C:\My Files" /p MyPackage.msix
MakeAppx pack /v /o /f MyMapping.txt /p MyPackage.msix
MakeAppx pack /m "MyApp\AppxManifest.xml" /f MyMapping.txt /p AppPackage.msix
MakeAppx pack /r /m "MyApp\AppxManifest.xml" /f MyMapping.txt /p ResourcePackage.msix
MakeAppx pack /v /h SHA256 /d "C:\My Files" /ep MyPackage.emsix /kf MyKeyFile.txt
MakeAppx pack /v /h SHA256 /d "C:\My Files" /ep MyPackage.emsix /kt

创建应用程序包Create an app bundle

应用程序包类似于应用包,但应用程序包可以减少用户下载的应用大小。An app bundle is similar to an app package, but a bundle can reduce the size of the app that users download. 例如,对于特定于语言的资源、各种图像缩放资源或适用于特定版本的 Microsoft DirectX 的资源,应用程序包很有用。App bundles are helpful for language-specific assets, varying image-scale assets, or resources that apply to specific versions of Microsoft DirectX, for example. 类似于创建加密应用包,还可以在绑定它时加密应用程序包。Similar to creating an encrypted app package, you can also encrypt the app bundle while bundling it. 要加密应用程序包,请使用 /ep 选项并指定是否使用密钥文件 (/kf) 或全局测试密钥 (/kt)。To encrypt the app bundle, use the /ep option and specify if you are using a key file (/kf) or the global test key (/kt). 有关创建加密捆绑包的详细信息,请参阅加密或解密程序包或捆绑包For more information on creating an encrypted bundle, see Encrypt or decrypt a package or bundle.

特定于 bundle 命令的选项:Options specific to the bundle command:

选项Option 说明Description
/bv/bv 指定捆绑包的版本号。Specifies the version number of the bundle. 版本号必须以句号分为四部分,格式为:<主要>.<次要>.<内部版>.<修订版>。The version number must be in four parts separated by periods in the form: <Major>.<Minor>.<Build>.<Revision>.
/f/f 指定映射文件。Specifies the mapping file.

请注意,如果未指定捆绑包版本,或如果已设置为“0.0.0.0”,则使用当前日期时间创建捆绑包。Note that if the bundle version is not specified or if it is set to "0.0.0.0" the bundle is created using the current date-time.

下面的用法示例演示了一些可能的 bundle 命令语法选项:The following usage examples show some possible syntax options for the bundle command:

MakeAppx bundle [options] /d <content directory> /p <output bundle name>
MakeAppx bundle [options] /f <mapping file> /p <output bundle name>
MakeAppx bundle [options] /d <content directory> /ep <encrypted output bundle name> /kf MyKeyFile.txt
MakeAppx bundle [options] /f <mapping file> /ep <encrypted output bundle name> /kt

下面的块包含 bundle 命令的示例:The following block contains examples for the bundle command:

MakeAppx bundle /v /d "C:\My Files" /p MyBundle.msixbundle
MakeAppx bundle /v /o /bv 1.0.1.2096 /f MyMapping.txt /p MyBundle.msixbundle
MakeAppx bundle /v /o /bv 1.0.1.2096 /f MyMapping.txt /ep MyBundle.emsixbundle /kf MyKeyFile.txt
MakeAppx bundle /v /o /bv 1.0.1.2096 /f MyMapping.txt /ep MyBundle.emsixbundle /kt

从程序包或捆绑包中解压缩文件Extract files from a package or bundle

除了打包和捆绑应用,MakeAppx.exe 还可以解压缩或解包现有程序包。In addition to packaging and bundling apps, MakeAppx.exe can also unpack or unbundle existing packages. 必须提供内容目录作为解压缩文件的目标。You must provide the content directory as a destination for the extracted files. 如果要从加密的程序包或捆绑包中解压缩文件,可以使用 /ep 选项并指定它是否应使用密钥文件 (/kf) 或全局测试密钥 (/kt) 进行解密,同时解密和解压缩文件。If you are trying to extract files from an encrypted package or bundle, you can decrypt and extract the files at the same time using the /ep option and specifying whether it should be decrypted using a key file (/kf) or the global test key (/kt). 有关解密程序包或捆绑包的详细信息,请参阅加密或解密程序包或捆绑包For more information on decrypting a package or bundle, see Encrypt or decrypt a package or bundle.

特定于 unpackunbundle 命令的选项:Options specific to unpack and unbundle commands:

选项Option 说明Description
/nd/nd 解压缩或解包软件包/捆绑包时,不执行解密。Does not perform decryption when unpacking or unbundling the package/bundle.
/pfn/pfn 将所有文件解压缩/解包到指定输出路径下的子目录中,以程序包或捆绑包的完整名称命名Unpacks/unbundles all files to a subdirectory under the specified output path, named after the package or bundle full name

下面的用法示例演示了一些可能的 unpackunbundle 命令语法选项:The following usage examples show some possible syntax options for the unpack and unbundle commands:

MakeAppx unpack [options] /p <input package name> /d <output directory>
MakeAppx unpack [options] /ep <encrypted input package name> /d <output directory> /kf <key file>
MakeAppx unpack [options] /ep <encrypted input package name> /d <output directory> /kt

MakeAppx unbundle [options] /p <input bundle name> /d <output directory>
MakeAppx unbundle [options] /ep <encrypted input bundle name> /d <output directory> /kf <key file>
MakeAppx unbundle [options] /ep <encrypted input bundle name> /d <output directory> /kt

下面的块包含 unpackunbundle 命令的使用示例:The following block contains examples for using the unpack and unbundle commands:

MakeAppx unpack /v /p MyPackage.msix /d "C:\My Files"
MakeAppx unpack /v /ep MyPackage.emsix /d "C:\My Files" /kf MyKeyFile.txt
MakeAppx unpack /v /ep MyPackage.emsix /d "C:\My Files" /kt

MakeAppx unbundle /v /p MyBundle.msixbundle /d "C:\My Files"
MakeAppx unbundle /v /ep MyBundle.emsixbundle /d "C:\My Files" /kf MyKeyFile.txt
MakeAppx unbundle /v /ep MyBundle.emsixbundle /d "C:\My Files" /kt

加密或解密程序包或捆绑包Encrypt or decrypt a package or bundle

MakeAppx.exe 工具也可以加密或解密现有程序包或捆绑包。The MakeAppx.exe tool can also encrypt or decrypt an existing package or bundle. 只需提供程序包名称、输出程序包名称,以及加密或解密是否应使用密钥文件 (/kf) 或全局测试密钥 (/kt)。You must simply provide the package name, the output package name, and whether encryption or decryption should use a key file (/kf) or the global test key (/kt).

Visual Studio 打包向导不提供加密和解密。Encryption and decryption are not available through the Visual Studio packaging wizard.

特定于 encryptdecrypt 命令的选项:Options specific to encrypt and decrypt commands:

选项Option 说明Description
/ep/ep 指定加密的应用包或捆绑包。Specifies an encrypted app package or bundle.

下面的用法示例演示了一些可能的 encryptdecrypt 命令语法选项:The following usage examples show some possible syntax options for the encrypt and decrypt commands:

MakeAppx encrypt [options] /p <package name> /ep <output package name> /kf <key file>
MakeAppx encrypt [options] /p <package name> /ep <output package name> /kt

MakeAppx decrypt [options] /ep <package name> /p <output package name> /kf <key file>
MakeAppx decrypt [options] /ep <package name> /p <output package name> /kt

下面的块包含 encryptdecrypt 命令的使用示例:The following block contains examples for using the encrypt and decrypt commands:

MakeAppx.exe encrypt /p MyPackage.msix /ep MyEncryptedPackage.emsix /kt
MakeAppx.exe encrypt /p MyPackage.msix /ep MyEncryptedPackage.emsix /kf MyKeyFile.txt

MakeAppx.exe decrypt /p MyPackage.msix /ep MyEncryptedPackage.emsix /kt
MakeAppx.exe decrypt p MyPackage.msix /ep MyEncryptedPackage.emsix /kf MyKeyFile.txt

密钥文件Key files

关键文件必须以包含字符串“[密钥]”的行开始,后跟描述要用于加密每个程序包的密钥的行。Key files must begin with a line containing the string "[Keys]" followed by lines describing the keys to encrypt each package with. 每个密钥由一对引号内的字符串表示,以空格或制表符分隔。Each key is represented by a pair of strings in quotation marks, separated by either spaces or tabs. 第一个字符串表示 base64 编码的 32 字节键 ID,第二个表示 base64 编码的 32 字节加密密钥。The first string represents the base64 encoded 32-byte key ID and the second represents the base64 encoded 32-byte encryption key. 密钥文件应该是一个简单的文本文件。A key file should be a simple text file.

密钥文件的示例:Example of a key file:

[Keys]
"OWVwSzliRGY1VWt1ODk4N1Q4R2Vqc04zMzIzNnlUREU="    "MjNFTlFhZGRGZEY2YnVxMTBocjd6THdOdk9pZkpvelc="

映射文件Mapping files

映射文件必须以包含字符串“[文件]”的行开始,后跟描述要添加到程序包的文件的行。Mapping files must begin with a line containing the string "[Files]" followed by lines describing the files to add to the package. 每个文件由一对引号内的路径表示,以空格或制表符分隔。Each file is described by a pair of paths in quotation marks, separated by either spaces or tabs. 每个文件表示其源(在磁盘上)和目标(在程序包中)。Each file represents its source (on disk) and destination (in the package). 映射文件应该是一个简单的文本文件。A mapping file should be a simple text file.

映射文件(无 /m 选项)的示例:Example of a mapping file (without the /m option):

[Files]
"C:\MyApp\StartPage.html"               "default.html"
"C:\Program Files (x86)\example.txt"    "misc\example.txt"
"\\MyServer\path\icon.png"              "icon.png"
"my app files\readme.txt"               "my app files\readme.txt"
"CustomManifest.xml"                    "AppxManifest.xml"

使用映射文件时,可以选择是否想要使用 /m 选项。When using a mapping file, you can choose whether you would like to use the /m option. /M 选项允许用户指定映射文件中的资源元数据,该文件将包含在生成的清单中。The /m option allows the user to specify the resource metadata in the mapping file to be included in the generated manifest. 如果使用 /m 选项,映射文件必须包含以“[ResourceMetadata]”行开始的部分,后跟指定“ResourceDimensions”和“ResourceId”的行。If you use the /m option, the mapping file must contain a section that begins with the line "[ResourceMetadata]", followed by lines that specify "ResourceDimensions" and "ResourceId." 应用程序包可以包含多个“ResourceDimensions”,但永远只会存在一个“ResourceId”。It is possible for an app package to contain multiple "ResourceDimensions", but there can only ever be one "ResourceId."

映射文件(带 /m 选项)的示例:Example of a mapping file (with the /m option):

[ResourceMetadata]
"ResourceDimensions"                    "language-en-us"
"ResourceId"                            "English"

[Files]
"images\en-us\logo.png"                 "en-us\logo.png"
"en-us.pri"                             "resources.pri"

由 MakeAppx.exe 执行的语义式验证Semantic validation performed by MakeAppx.exe

MakeAppx.exe 执行有限的语义式验证,旨在捕获最常见的部署错误并帮助确保应用包有效。MakeAppx.exe performs limited sematic validation that is designed to catch the most common deployment errors and help ensure that the app package is valid. 如果想要在使用 MakeAppx.exe 时跳过验证,请参阅 /nv 选项。See the /nv option if you want to skip validation while using MakeAppx.exe.

此验证确保:This validation ensures that:

  • 在程序包清单中引用的所有文件都包含在应用包中。All files referenced in the package manifest are included in the app package.
  • 应用程序没有两个相同的密钥。An application does not have two identical keys.
  • 应用程序不会注册此列表中的禁用协议:SMB、FILE、MS-WWA-WEB、MS-WWA。An application does not register for a forbidden protocol from this list: SMB, FILE, MS-WWA-WEB, MS-WWA.

这不是完整的语义式验证,因为它仅用于捕获常见错误。This is not a complete semantic validation as it is only designed to catch common errors. 不能保证通过 MakeAppx.exe 生成的程序包均可安装。Packages built by MakeAppx.exe are not guaranteed to be installable.