使用 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.exe。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.exe 或 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.exe 或 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. 如果无法找到作为默认设置或将始终与用户的上下文匹配的特定语言、周围地区或其他限定符的候选资源,将显示此警告。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. 在运行时,对于特定的用户配置(如用户的语言首选项或主位置Settings > & 语言 > 区域 & 语言),用于检索资源的 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. 以下构建系统应使用 resourcepack 命令:必须创建一个 PRI 文件,该文件中包含其他的资源变体,而且需要验证以确保不为该变体添加任何新资源。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 特定格式索引器将预生成的 PRI 文件添加到来自其他组件(如类库、程序集、SDK 和 DLL)的包的 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 配置确保组件资源具有自己的子资源地图,且不与其所在的应用相冲突。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.