應用程式套件更新App package updates

最新的 Windows 應用程式套件更新已最佳化,目的是確保系統只會下載必要的應用程式變更位元來更新現有的 Windows 應用程式。Updating modern Windows app packages is optimized to ensure that only the essential changed bits of the app are downloaded to update an existing Windows app.

AppxBlockMap.xml 檔案中的中繼資料Metadata in the AppxBlockMap.xml file

概括而言,在建立套件期間,一部分的中繼資料會隨之建立,並且儲存在應用程式套件檔案中 (.appx 或 .msix),而 Windows 可藉此識別出獨有的套件部份。At a high level, during package creation, a piece of metadata is created and stored in the app package file (.appx or .msix) which allows parts of the package to be uniquely identified by Windows. 更新應用程式套件時,Windows 會使用中繼資料檔案來比較舊套件與新套件,並決定要下載到裝置的項目。When updating an app package, Windows uses the metadata file to compare the old package to the new package and determine what needs to be downloaded to the device.

由於中繼資料可讓套件部分有唯一的身分識別,這表示差異更新機制完全可用在任何套件版本之間 (假設來源套件的版本比目標套件的版本低)。Since the metadata allows parts of the package to be uniquely identified, this means the differential update machinery fully functions from any version of a package to any other version of a package (assuming the source package has a lower version than the target package).

中繼資料包含在 AppxBlockMap.xml 檔案中 (前述的中繼資料)。The metadata is contained in the AppxBlockMap.xml file (the aforementioned metadata). AppxBlockMap.xml 檔案是 XML 檔案,其中包含套件中檔案相關資訊的二維清單。The AppxBlockMap.xml file is an XML file that contains a two dimensional list of information about files in the package. 第一個維度輸出檔案的詳細資料概觀 (例如名稱和大小),第二個維度提供該檔案每個 64KB 配量 (也就是「區塊」) 的 SHA2-256 雜湊表示法。The first dimension lays out high level details on the file (e.g., name and size) and the second dimension provides SHA2-256 hash representations of each 64KB slice of that file (the "block").

以下是 AppxBlockMap.xml 檔案的範例。Here's a sample of an AppxBlockMap.xml file.

<!--?xml version="1.0" encoding="UTF-8"?-->
<blockmap hashmethod="http://www.w3.org/2001/04/xmlenc#sha256" 
          xmlns="http://schemas.microsoft.com/appx/2010/blockmap">
  <file lfhsize="66" size="101188" name="asset1.jpg">
    <block hash="2bidNE0JyaO+FjaTpRe0g8HzUCblUf/cfBcTXiZR74c="/>
    <block hash="+jeFwKrGk5gw9wSICWsWRtEQXwcLC7af4EWS7DgrAkY="/>
  </file>
  <file lfhsize="61" size="108823" name="asset2.jpg">
    <block hash="u0+5S0GOzwyAfYx54tKycZyHRBYm2ybvq27dkIKqDsQ="/>
    <block hash="F9h0FRMetL6BNCszAYB0bgyx2KWN+dO1bls4Q9m267c="/>
  </file>
  ...
</blockmap>

第一個檔案 (asset1.jpg) 有兩個區塊雜湊。 第一個雜湊代表檔案的第一個 64KB 區塊,而第二個雜湊代表剩餘的 35 KB - 假設檔案為 101188 個位元組。The first hash represents the first 64KB block of the file and the second hash represents the remaining 35KB - given the file is 101188 bytes.

在更新期間,如果修改了該檔案的第二個區塊,則雜湊也會為了反映此變更而更新。During an update, if the second block of that file is modified, the hash is also updated to reflect that. 下載元件會將第二個區塊往下拉,並重複使用舊套件中第一個未變更的區塊。The download component pulls down the second block and reuses the first unchanged block from the old package.

在更大的規模中,如果整個檔案未變更 (根據一組未變更的完整區塊來判斷),則可以從現有套件中重複使用該檔案,藉此來節省時間和資源。On a larger scale, if an entire file does not change (determined by a full set of blocks not changing), that file can be reused from the existing package, saving time and resources.

應用程式更新的限制App update constraints

更新會在相同的套件系列內執行Updates are performed within the same package family

套件系列由套件名稱和發行者所組成。The package family is comprised of the Package Name and Publisher. 為了能夠進行更新,新的套件中繼資料必須與先前安裝的套件相同。To be able to update, the new package metadata will need to be the same as the previously installed package.

應用程式更新必須累計為更高版本App updates must increment to a higher version

一般而言,應用程式更新會要求新套件版本須高於目前版本。In general, app updates require the version of the new package to be higher than the current one. 根據預設,應用程式更新程序不會允許安裝版本較低的套件。The app update process will not allow packages with lower versions to be installed by default. 從 Windows 10 版本 1809 開始,您可以使用 ForceUpdateToAnyVersion 在提供覆寫參數作為更新引數的一部分時,允許安裝版本較低的套件。Starting in Windows 10 version 1809, you can use ForceUpdateToAnyVersion to allow lower version packages to be installed when an override switch is provided as part of the update arguments. 目前可在 PowerShell 中使用 ForceUpdateFromAnyVersion 選項、透過 PackageManager APIEnterpriseModernAppManagement CSPAppInstaller 檔案取得該套件。It is currently available in PowerShell using the ForceUpdateFromAnyVersion option, via PackageManager API, EnterpriseModernAppManagement CSP and in the AppInstaller file.

注意

如果您在 Windows Store 中的應用程式上使用 ForceUpdateToAnyVersion,Windows Update 會自動更新為最新的適用版本。If you use ForceUpdateToAnyVersion on an app from the Windows Store, Windows Update will automatically update the to the latest applicable version.

應用程式更新套件可以有不同的架構App update package can have a different architecture

目前所安裝應用程式套件的更新套件可以屬於不同架構,只要部署更新套件的 OS 支援新的架構即可。The update package to the currently installed app package can be of a different architecture as long as the new architecture is supported on the OS where it is being deployed to. 例如:如果您的 x64 Windows 10 裝置上已安裝 x86 版本的 MyFavApp(v1.0.0.0),而更新套件 (v2.0.0.0) 是 x64 版本:MyFavApp(1.0.0.0) 會成功更新為 MyFavApp(v2.0.0.0)。For example: If you have x86 version of MyFavApp(v1.0.0.0) installed on a x64 Windows 10 device and the update package(v2.0.0.0) is x64 version: MyFavApp(1.0.0.0) will be updated to MyFavApp(v2.0.0.0) successfully.

套件可以從 MSIX 更新為 MSIXbundlePackages can update from an MSIX to an MSIXbundle

更新套件可以從 MSIX 套件更新為 MSIXbundle 套件,但不能反過來。An update package can go from MSIX package to an MSIXbundle package but not vice-versa. 安裝 MSIXbundle 後,套件更新必須仍然是個組合。When an MSIXbundle is installed, the package update will need to remain a bundle.

最佳化差異更新技術Optimize differential update technology

有幾種方式可確保差異更新技術已達到最佳化的上限。There are a few ways to ensure that the differential update technology is optimized to the max.

  • 套件中都是小型檔案 - 這麼做可確保在進行影響整個檔案的變更後,更新仍然是個小型作業。Keep files in the package small - doing this will ensure that if a change is needed that would impact the full file, the update would still be small.
  • 如果可能,檔案的變更應採累加方式 - 累加變更可確保終端使用者裝置只需下載有變更的區塊。Changes to files should be additive if possible - additive changes will ensure that end-user devices only download those changed blocks.
  • 如果可能,檔案的變更應包含在 64KB 區塊中 - 如果您的應用程式有大量檔案,並且必須在某個檔案中進行變更,那麼將變更包含到一組區塊會有很大的幫助。Changes to files should be contained to 64KB blocks if possible - if your app does have large files and requires changes to the middle of a file, containing changes to a set of blocks will help significantly.