使用 MakePri.exe 來手動編譯資源Compile resources manually with MakePri.exe

MakePri.exe 是一個命令列工具,您可以用來建立和傾印 PRI 檔案。MakePri.exe is a command line tool that you can use to create and dump PRI files. 其做為 MSBuild 的一部分整合到 Microsoft Visual Studio 中,但用於手動建立套件或自訂組建系統也很有用。It is integrated as part of MSBuild within Microsoft Visual Studio, but it could be useful to you for creating packages manually or with a custom build system.

注意

當您在安裝 Windows 軟體發展工具組時,檢查UWP 受管理應用程式的 Windows SDK選項時,會安裝 MakePri。MakePri.exe is installed when you check the Windows SDK for UWP Managed Apps option while installing the Windows Software Development Kit. 它會安裝到路徑%WindowsSdkDir%bin\<WindowsTargetPlatformVersion>\x64\makepri.exe (以及針對其他架構命名的資料夾中)。It is installed to the path %WindowsSdkDir%bin\<WindowsTargetPlatformVersion>\x64\makepri.exe (as well as in folders named for the other architectures). 例如: C:\Program Files (x86)\Windows Kits\10\bin\10.0.17713.0\x64\makepri.exeFor example, C:\Program Files (x86)\Windows Kits\10\bin\10.0.17713.0\x64\makepri.exe.

本節內容In this section

主題Topic 描述Description
MakePri.exe 命令列選項MakePri.exe command-line options MakePri.exe 有一組命令 createconfigdumpnewresourcepackversionedMakePri.exe has the set of commands createconfig, dump, new, resourcepack, and versioned. 本主題詳述命令列選項的使用。This topic details the command-line options for their use.
MakePri.exe 設定檔MakePri.exe configuration file 本主題說明 MakePri.exe XML 設定檔的結構描述。This topic describes the schema of the MakePri.exe XML configuration file.
MakePri.exe 格式特定的索引子MakePri.exe format-specific indexers 本主題說明 MakePri.exe 用來產生資源索引的格式特定索引子。This topic describes the format-specific indexers used by the MakePri.exe tool to generate its index of resources.

MakePri.exe 命令列選項MakePri.exe command-line options

MakePri.exe 有一組命令 createconfigdumpnewresourcepackversionedMakePri.exe has the set of commands createconfig, dump, new, resourcepack, and versioned. 如需其使用的詳細資訊,請參閱 MakePri.exe 命令列選項For details of their use, see MakePri.exe command-line options.

MakePri.exe 設定MakePri.exe configuration

PRI XML 設定檔會指出如何編製什麼資源的索引。The PRI XML configuration file dictates how and what resources are indexed. 設定 XML 的結構描述在 MakePri.exe 設定中描述。The schema of the configuration XML is described in MakePri.exe configuration.

格式特定的索引子Format-specific indexers

MakePri.exe 通常搭配 newversionedresourcepack 選項使用。MakePri.exe is typically used with the new, versioned, and resourcepack options. 在這些案例中,它會編制來源檔案的索引來產生資源的索引。In those cases it indexes source files to generate an index of resources. MakePri.exe 使用各種個別索引子來讀取不同來源的資源檔案或資源的容器。MakePri.exe uses various individual indexers to read different source resource files or containers for resources. 最簡單的索引子是資料夾索引子,它會為資源如 .jpg.png 影像編制資料夾內容的索引。The simplest indexer is the folder indexer, which indexes the contents of a folder for resources such as .jpg or .png images. 如需詳細資訊,請參閱 MakePri.exe 格式特定的索引子For more info, see MakePri.exe format-specific indexers.

MakePri.exe 警告和錯誤訊息MakePri.exe warnings and error messages

找到語言「<語言」 > ' 的資源,但找不到預設語言的資源:「<語言 >」。Resources found for language(s) '<language(s)>' but no resources found for default language(s): '<language(s)>'. 變更預設語言,或以預設語言限定資源。Change the default language or qualify resources with the default language.

當 MakePri 或 MSBuild 探索到標示了語言辨識符號之指定名稱資源的檔案或字串資源,但未找到預設語言的候選項時,就會顯示此警告。This warning is displayed when MakePri.exe or MSBuild discovers files or string resources for a given named resource that appear to be marked with language qualifiers, but no candidate is found for a default language. 在檔案和資料夾名稱中使用限定詞的程序會在針對語言、縮放比例及其他限定詞量身打造您的資源中說明。The process for using qualifiers in file and folder names is described in Tailor your resources for language, scale, and other qualifiers. 檔案或資料夾名稱中可能有語言名稱,但是找不到確切符合預設語言的任何資源。A file or folder may have a language name in it, but no resources are discovered that are qualified for the exact default language. 例如,如果專案使用「en-US」做為預設語言,並且有一個名為「de/logo.png」的檔案,但是沒有任何檔案標示「en-US」的預設語言,就會出現此警告。For example, if a project uses "en-US" as the default language and has a file named "de/logo.png", but does not have any files that are marked with the default language "en-US", this warning will appear. 為移除此警告,檔案或字串資源應符合預設語言,或者應該變更預設語言。In order to remove this warning, either file(s) or string resource(s) should be qualified with the default language, or the default language should be changed. 若要變更預設語言,在 Visual Studio 中保持您的解決方案為開啟狀態下,開啟 Package.appxmanifestTo change the default language, with your solution open in Visual Studio, open Package.appxmanifest. 在 [應用程式] 索引標籤上,確認預設語言有適當地設定 (例如,「en」或「en-US」)。On the Application tab, confirm that the Default language is set appropriately (for example, "en" or "en-US").

沒有為 '' 提供預設或中性的資源。No default or neutral resource given for ''. 在抓取資源時,應用程式可能會擲回特定使用者設定的例外狀況。The application may throw an exception for certain user configurations when retrieving the resources.

當 MakePri 或 MSBuild 發現的檔案或資源標示為不清楚資源的語言限定詞時,就會顯示此警告。This warning is displayed when MakePri.exe or MSBuild discovers files or resources that appear to be marked with language qualifiers for which the resources are unclear. 雖然有限定詞,但是並不保證特定資源候選項目可以因為該資源識別碼在執行階段而傳回。There are qualifiers, but there is no guarantee that a particular resource candidate can be returned for that resource identifier at run time. 如果找不到特定語言的資源候選項目、HomeRegion 或其他限定詞為預設值,或者始終與使用者的內容相符,將會顯示此警告。If no resource candidate for a particular language, homeregion, or other qualifier can be found that is a default or will always match the context of a user, this warning will be displayed. 在執行時間,針對特定使用者設定(例如使用者的語言喜好設定或首頁位置(設定 > 時間 & 語言 > 區域 & 語言),用來捕獲資源的 api 可能會擲回未預期的例外狀況。At run time, for particular user configurations such as a user's language preferences or home location (Settings > Time & Language > Region & language), the APIs used to retrieve the resource may throw an unexpected exception. 為了移除此警告,應該提供預設資源,例如專案的預設語言或全球首頁區域 (homeregion-001) 中的資源。In order to remove this warning, default resources should be provided, such as a resource in the project's default language or global home region (homeregion-001).

在組建系統中使用 MakePri.exeUsing MakePri.exe in a build system

組建系統應該根據要建置專案的類型使用 MakePri.exe newversionedresourcepack 命令。Build systems should use the MakePri.exe new, versioned, or resourcepack command, depending on the type of project being built. 建立新的 PRI 檔案的組建系統應該使用 new 命令。Build systems that create a fresh PRI file should use the new command. 必須透過反覆運算確保內部位移之相容性的組建系統可以使用 versioned 命令。Build systems that must ensure compatibility of internal offsets through iterations can use the versioned command. 必須建立包含資源額外變體的 PRI 檔案的組建系統,經過驗證以確保未加入任何新的資源到該變體時,應該使用 resourcepack 命令。Build systems that must create a PRI file that contains additional variants of resources, with validation to ensure that no new resources are added for that variant, should use the resourcepack command.

需要明確控制已編製索引之來源檔案的組建系統,可以使用 ResFiles 索引子而不是編製資料夾的索引。Build systems that require explicit control over source files that get indexed can use the ResFiles indexer instead of indexing a folder. 組建系統也可以使用多個具有不同格式特定索引子的索引證來產生單一 PRI 檔案。Build systems can also use multiple index passes with different format-specific indexers to generate a single PRI file.

組建系統也可以使用 PRI 格式特定的索引子,從其他元件例如類別庫、組件、SDK 和 DLL,將預先建置的 PRI 檔案新增到 PRI。Build systems can also use the PRI format-specific indexer to add pre-built PRI files into the PRI for the package from other components, such as class libraries, assemblies, SDKs, and DLLs.

當為其他元件、類別庫、組件、DLL 和 SDK 建置 PRI 檔案時,initialPath 設定應用來確保元件資源有自己的子資源地圖,不會與包含該地圖的 App 相衝突。When PRI files are built for other components, class libraries, assemblies, DLLs, and SDKs, the initialPath configuration should be used to ensure component resources have their own sub resource maps that don't conflict with the app they're included in.