创建和转换源内容组映射Create and convert a source content group map

若要为应用程序准备好进行流式处理,需要创建内容组映射。To get your app ready for streaming install, you'll need to create a content group map. 本文介绍有关创建和转换内容组映射的具体信息,同时提供一些相关提示和技巧。This article will help you with the specifics of creating and converting a content group map while providing some tips and tricks along the way.

创建源内容组映射Creating the source content group map

需要创建 SourceAppxContentGroupMap.xml 文件,然后使用 Visual Studio 或 MakeAppx.exe 工具将此文件转换为最终版本:AppxContentGroupMap.xmlYou'll need to create a SourceAppxContentGroupMap.xml file, and then either use Visual Studio or the MakeAppx.exe tool to convert this file to the final version: AppxContentGroupMap.xml. 从头开始创建 AppxContentGroupMap.xml可跳过一个步骤,但由于 AppxContentGroupMap.xml 中不允许使用通配符(它们非常有用),因此建议(通常也更容易)创建 SourceAppxContentGroupMap.xml 并进行转换。It's possible to skip a step by creating the AppxContentGroupMap.xml from scratch, but it's recommended (and generally easier) to create the SourceAppxContentGroupMap.xml and convert it, since wildcards are not allowed in the AppxContentGroupMap.xml (and they're really helpful).

让我们来看一看应用程序流式安装非常有用的简单方案。Let's walk through a simple scenario where app streaming install is beneficial.

假设您已经创建了一个游戏,但最终应用程序的大小超过 100 GB。Say you've created a game, but the size of your final app is over 100 GB. 这可能需要很长时间才能从 Microsoft Store 下载,这可能很不方便。That's going to take a long time to download from the Microsoft Store, which can be inconvenient. 如果选择使用应用程序流安装,则可以指定应用程序文件的下载顺序。If you choose to use app streaming install, you can specify the order in which your app's files are downloaded. 告知应用商店先下载必要的文件,用户就能够尽快地使用应用,同时在后台下载其他不重要的文件。By telling the Store to download essential files first, the user will be able to engage with your app sooner while other non-essential files are downloaded in the background.

备注

使用应用程序流安装很大程度上依赖于应用程序的文件组织。Using app streaming install heavily relies on your app's file organization. 建议你在应用程序流式处理安装时尽快考虑应用的内容布局,以便更轻松地将应用程序的文件分段。It's recommended that you think about your app's content layout with respect to app streaming install as soon as possible to make segmenting your app's files simpler.

首先,创建 SourceAppxContentGroupMap.xml 文件。First, we'll create a SourceAppxContentGroupMap.xml file.

在深入了解详细信息前,下面是一个简单的完整 SourceAppxContentGroupMap.xml 文件示例:Before we get in to the details, here's an example of a simple, complete SourceAppxContentGroupMap.xml file:

<?xml version="1.0" encoding="utf-8"?>  
<ContentGroupMap xmlns="http://schemas.microsoft.com/appx/2016/sourcecontentgroupmap" 
                 xmlns:s="http://schemas.microsoft.com/appx/2016/sourcecontentgroupmap"> 
    <Required>
        <ContentGroup Name="Required">
            <File Name="StreamingTestApp.exe"/>
        </ContentGroup>
    </Required>
    <Automatic>
        <ContentGroup Name="Level2">
            <File Name="Assets\Level2\*"/>
        </ContentGroup>
        <ContentGroup Name="Level3">
            <File Name="Assets\Level3\*"/>
        </ContentGroup>
    </Automatic>
</ContentGroupMap>

内容组映射有两个主要组件:所需分区,其中包含所需内容组;自动分区,其中可包含多个自动内容组。There are two main components to a content group map: the required section, which contains the required content group, and the automatic section, which can contain multiple automatic content groups.

所需内容组Required content group

所需内容组是 SourceAppxContentGroupMap.xml<Required>元素内的单一内容组。The required content group is a single content group within the <Required> element of the SourceAppxContentGroupMap.xml. 所需内容组应包含以最少用户体验启动应用所需的所有重要文件。A required content group should contain all of the essential files necessary to launch the app with the minimal user experience. 由于 .NET Native 编译,所有代码(应用程序可执行文件)都必须包含在所需组中,资产和其他文件则包含在自动组中。Due to .NET Native compilation, all code (the application executable) must be part of the required group, leaving assets and other files for the automatic groups.

例如,如果应用是一款游戏,所需组可能包含用于主菜单或游戏主屏幕中的文件。For example, if your app is a game, the required group may include files used in the main menu or game home screen.

下面是原始 SourceAppxContentGroupMap.xml 示例文件的代码片段:Here's the snippet from our original SourceAppxContentGroupMap.xml example file:

<Required>
    <ContentGroup Name="Required">
        <File Name="StreamingTestApp.exe"/>
    </ContentGroup>
</Required>

下面是几个需注意的重要事项:There are a few important things to notice here:

  • <Required> 元素内的 <ContentGroup>必须命名为“所需”。The <ContentGroup> within the <Required> element must be named "Required." 此名称仅保留供所需内容组使用,不能用于最终内容组映射中的任何其他 <ContentGroup>This name is reserved for the required content group only, and cannot be used with any other <ContentGroup> in the final content group map.
  • 只有一个 <ContentGroup>There's only one <ContentGroup>. 这样做是有意的,因为应只存在一组必需文件。This is intentional, since there should be only one group of essential files.
  • 该文件在此示例中是一个 .exe 文件。The file in this example is a single .exe file. 所需内容组并不限于一个文件,可存在多个文件。A required content group isn't restricted to one file, there can be several.

要开始编写此文件,简单的方法是在最喜欢的文本编辑器中打开一个新页面,快速将文件“另存为”至应用的项目文件夹,并将新创建的文件命名为:SourceAppxContentGroupMap.xmlAn easy way to get started writing this file is to open up a new page in your favorite text editor, do a quick "Save As" of your file to your app's project folder, and name your newly created file: SourceAppxContentGroupMap.xml.

重要

如果要开发 c + + 应用,则需要调整的文件属性 SourceAppxContentGroupMap.xmlIf you are developing a C++ app, you will need to adjust the file properties of your SourceAppxContentGroupMap.xml. Content 属性设置为 trueFile Type 属性设置为 XML 文件Set the Content property to true and the File Type property to XML File.

创建 SourceAppxContentGroupMap.xml 时,在文件名中使用通配符会有所帮助,有关详细信息,请参阅使用通配符的提示和技巧部分。When you're creating the SourceAppxContentGroupMap.xml, it's helpful to take advantage of using wildcards in file names, for more info, see the Tips and tricks for using wildcards section.

如果使用 Visual Studio 开发应用,建议将此文件包含在所需内容组中:If you developed your app using Visual Studio, it's recommended that you include this in your required content group:

<File Name="*"/>
<File Name="WinMetadata\*"/>
<File Name="Properties\*"/>
<File Name="Assets\*Logo*"/>
<File Name="Assets\*SplashScreen*"/>

添加单个通配符文件名将包括 Visual Studio 中添加到项目目录的文件,例如应用可执行文件或 DLL。Adding the single wildcard file name will include files added to the project directory from Visual Studio, such as the app executable or DLLs. WinMetadata 和“属性”文件夹包含 Visual Studio 生成的其他文件夹。The WinMetadata and Properties folders are to include the other folders Visual Studio generates. 资产通配符用于为要安装的应用选择必需的徽标和 SplashScreen 图像。The Assets wildcards are to select the Logo and SplashScreen images that are necessary for the app to be installed.

请注意,不能在文件结构的根处使用双通配符“**”将每个文件包含在项目中,因为尝试将 SourceAppxContentGroupMap.xml 转换为最终 AppxContentGroupMap.xml 时此操作将失败。Note that you cannot use the double wild card, "**", at the root of the file structure to include every file in the project since this will fail when attempting to convert SourceAppxContentGroupMap.xml to the final AppxContentGroupMap.xml.

此外,还需注意内存占用文件(AppxManifest.xml、AppxSignature.p7x、resources.pri 等)不应包含在内容组映射中。It's also important to note that footprint files (AppxManifest.xml, AppxSignature.p7x, resources.pri, etc.) should not be included in the content group map. 如果内存占用文件包含指定的通配符文件名之一,它们将会忽略。If footprint files are included within one of the wildcard file names you specify, they will be ignored.

自动内容组Automatic content groups

自动内容组是用户与已下载的内容组进行交互时在后台下载的资产。Automatic content groups are the assets that are downloaded in the background while the user is interacting with the already downloaded content groups. 这些组中包含对启动应用影响不大的所有其他文件。These contain any additional files that are not essential to launching the app. 例如,可将自动内容组分解为不同的级别,将每一级别定义为单独的内容组。For example, you could break up automatic content groups in to different levels, defining each level as a separate content group. 如所需内容组部分中所述:由于 .NET Native 编译,所有代码(应用程序可执行文件)都必须包含在所需组中,资产和其他文件则包含在自动组中。As noted in the required content group section: due to .NET Native compilation, all code (the application executable) must be part of the required group, leaving assets and other files for the automatic groups.

下面从 SourceAppxContentGroupMap.xml 示例深入了解自动内容组:Let's take a closer look at the automatic content group from our SourceAppxContentGroupMap.xml example:

<Automatic>
    <ContentGroup Name="Level2">
        <File Name="Assets\Level2\*"/>
    </ContentGroup>
    <ContentGroup Name="Level3">
        <File Name="Assets\Level3\*"/>
    </ContentGroup>
</Automatic>

自动组的布局非常类似于所需组的布局,以下几项例外:The layout of the automatic group is pretty similar to the required group, with a few exceptions:

  • 存在多个内容组。There are multiple content groups.
  • 除了为所需内容组保留的名称“必需”外,自动内容组可具有唯一的名称。Automatic content groups can have unique names except for the name "Required" which is reserved for the required content group.
  • 自动内容组不能包含所需内容组中的任何文件。Automatic content groups cannot contain any files from the required content group.
  • 自动内容组可包含同时位于其他自动内容组中的文件。An automatic content group can contain files that are also in other automatic content groups. 这些文件只会下载一次,并且将使用包含它们的首个自动内容组进行下载。The files will be downloaded only once, and will be downloaded with the first automatic content group that contains them.

使用通配符的提示和技巧Tips and tricks for using wildcards

内容组映射的文件布局始终与项目根文件夹相关。The file layout for content group maps is always relative to your project root folder.

在本例中,两个 <ContentGroup> 元素中均使用了通配符,用于检索“Assets\Level2”或“Assets\Level3”的一个文件级别内的所有文件。In our example, wildcards are used within both <ContentGroup> elements to retrieve all files within one file level of "Assets\Level2" or "Assets\Level3." 如果使用的文件夹结构较深,可以使用双通配符:If you're using a deeper folder structure, you can use the double wildcard:

<ContentGroup Name="Level2">
    <File Name="Assets\Level2\**"/>
</ContentGroup>

还可以针对文件名配合使用通配符和文本。You can also use wildcards with text for file names. 例如,如果想要将每个文件包含在文件名包含“Level2”的“资产”文件夹中,可以使用如下所示的内容:For example, if you want to include every file in your "Assets" folder with a file name that contains "Level2" you can use something like this:

<ContentGroup Name="Level2">
    <File Name="Assets\*Level2*"/>
</ContentGroup>

将 SourceAppxContentGroupMap.xml 转换为 AppxContentGroupMap.xmlConvert SourceAppxContentGroupMap.xml to AppxContentGroupMap.xml

若要将 SourceAppxContentGroupMap.xml 转换为最终版本 AppxContentGroupMap.xml,可使用 Visual Studio 2017 或 MakeAppx.exe 命令行工具。To convert the SourceAppxContentGroupMap.xml to the final version, AppxContentGroupMap.xml, you can use Visual Studio 2017 or the MakeAppx.exe command line tool.

使用 Visual Studio 转换内容组映射:To use Visual Studio to convert your content group map:

  1. 向项目文件夹添加 SourceAppxContentGroupMap.xmlAdd the SourceAppxContentGroupMap.xml to your project folder
  2. 在“属性”窗口中将 SourceAppxContentGroupMap.xml 的生成操作更改为“AppxSourceContentGroupMap”Change the Build Action of the SourceAppxContentGroupMap.xmlto "AppxSourceContentGroupMap" in the Properties window
  3. 在解决方案资源管理器中右键单击该项目Right click the project in the solution explorer
  4. 导航到“应用商店”->“转换内容组映射文件”Navigate to Store -> Convert Content Group Map File

如果未在 Visual Studio 中开发应用,或者只是更喜欢使用命令行,请使用 MakeAppx.exe 工具转换 SourceAppxContentGroupMap.xmlIf you didn't develop your app in Visual Studio, or if you just prefer using the command line, use the MakeAppx.exe tool to convert your SourceAppxContentGroupMap.xml.

简单的 MakeAppx.exe 命令可能如下所示:A simple MakeAppx.exe command might look something like this:

MakeAppx convertCGM /s MyApp\SourceAppxContentGroupMap.xml /f MyApp\AppxContentGroupMap.xml /d MyApp\

/S 选项指定指向 SourceAppxContentGroupMap.xml 的路径,/f 指定指向 AppxContentGroupMap.xml 的路径。The /s option specifies the path to the SourceAppxContentGroupMap.xml, and /f specifies the path to the AppxContentGroupMap.xml. 最后一个选项 /d 指定应用于扩展文件名通配符的目录,在此情况下,它是应用项目目录。The final option, /d, specifies which directory should be used for expanding file name wildcards, in this case, its the app project directory.

若要详细了解可与 MakeAppx.exe 配合使用的选项,请打开一个命令提示符,导航到 MakeAppx.exe 并输入:For more information about options you can use with MakeAppx.exe, open a command prompt, navigate to MakeAppx.exe and enter:

MakeAppx convertCGM /?

这就是使最终 AppxContentGroupMap.xml 可供应用使用需要进行的所有操作!That's all you'll need to get your final AppxContentGroupMap.xml ready for your app! 在应用完全准备好 Microsoft Store 之前,还有更多工作要做。There's still more to do before your app is fully ready for the Microsoft Store. 有关将流式处理安装添加到应用的完整过程的详细信息,请查看 此博客文章For more information on the complete process of adding streaming install to your app, check out this blog post.