使用 MakeAppx.exe 建立 MSIX 套件或套件組合Create an MSIX package or bundle with MakeAppx.exe

MakeAppx.exe 會 ( msixbundle 或 .appxbundle) 建立應用程式套件 ( 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 來開發 App,建議您使用 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 \ < 組建編號 >\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 \ < 組建編號 >\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> 建立的套件名稱。The name of the package created. 這是附加 msix 或 .appx 的檔案名。This is the file name appended with .msix or .appx.
<加密的輸出套件名稱><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> 封裝名稱。The name of the package. 這是附加 msix 或 .appx 的檔案名。This is the file name appended with .msix or .appx.
<加密的輸入套件名稱><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> 建立的套件組合名稱。The name of the bundle created. 這是附加 msixbundle 或 .appxbundle 的檔案名。This is the file name appended with .msixbundle or .appxbundle.
<加密的輸出套件組合名稱><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> 套件組合的名稱。The name of the bundle. 這是附加 msixbundle 或 .appxbundle 的檔案名。This is the file name appended with .msixbundle or .appxbundle.
<加密的輸入套件組合名稱><encrypted input bundle name> 加密套件組合的名稱。The name of the encrypted bundle. 這是附加 emsixbundle 或. eappxbundle 的檔案名。This is the file name appended with .emsixbundle or .eappxbundle.
<內容目錄><content directory> 應用程式套件或套件組合內容的路徑。Path for the app package or bundle content.
<對應檔案><mapping file> 指定套件來源和目的地的檔案名稱。File name that specifies the package source and destination.
<輸出目錄><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> 建立區塊對應時使用的演算法。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

金鑰檔案的開頭必須有一行 "[Keys]" 字串,後面接著要用來加密每個套件的金鑰。Key files must begin with a line containing the string "[Keys]" followed by lines describing the keys to encrypt each package with. 每個金鑰由一組以引號括住的字串表示,以空格或 Tab 鍵分隔。Each key is represented by a pair of strings in quotation marks, separated by either spaces or tabs. 第一個字串代表 base64 編碼的 32 位元金鑰識別碼,第二個字串代表 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

對應檔案的開頭必須有一行 "[Files]" 字串,後面接著要加入套件的檔案。Mapping files must begin with a line containing the string "[Files]" followed by lines describing the files to add to the package. 每個檔案由一組以引號括住的路徑表示,以空格或 Tab 鍵分隔。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.