> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XBOX 主机游戏打包入门

> XBOX 主机游戏打包入门

按照以下步骤创建可在 Microsoft Game Development Kit 上旁加载测试的 XVC 包，然后提交到合作伙伴中心进行发布。

## 从合作伙伴中心获取产品身份信息

你的包会引用在合作伙伴中心中分配给你游戏的产品身份，包括你的发行商身份、PackageFamilyName、MSAAppId 和 TitleId。设置你的产品，然后从 **Game Setup | Identity** 页面获取这些信息，以在 MicrosoftGame.config 中使用。

1. 如果尚未注册，请[注册 ID@XBOX 项目](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/pc-dev/tutorials/pc-e2e-guide/e2e-register-id-at-xbox)并[创建合作伙伴中心账户](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/pc-dev/tutorials/pc-e2e-guide/e2e-creating-partnercenter-account)。
2. 在合作伙伴中心为你的游戏[创建初始产品定义](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/pc-dev/tutorials/pc-e2e-guide/e2e-creating-partnercenter-product-definition)。
3. 在产品的 **Game Setup | Identity** 页面上，查找上述身份值。

## 在包含其余游戏内容的根文件夹中创建 MicrosoftGame.config 文件

本文后面提供了一个示例 MicrosoftGame.config XML 文件。可将此示例与 [MicrosoftGame.config 编辑器](/build/core-features/common/game-config/MicrosoftGameConfig-Editor)结合使用，该编辑器可简化 .config 文件的创建，并可自动从合作伙伴中心项目同步 ID 与名称值。

## 创建用于在 shell 和 Microsoft 应用市场包中显示的图标

对于以下 MicrosoftGame.config 示例中列出的每个图像，请将相应文件按指定尺寸缩放后放入游戏的根文件夹。或者，你也可以将图像资源放入子目录中，并相应调整 `ShellVisuals` 图标路径。[MicrosoftGame.config 编辑器](/build/core-features/common/game-config/MicrosoftGameConfig-Editor)可根据单个源图像生成这些图像。

## 安装 Microsoft Game Development Kit (GDK)（包括打包工具 makepkg.exe）

默认情况下，Microsoft Game Development Kit (GDK) 命令提示符位于以下文件夹：`C:\Program Files (x86)\Microsoft GDK\Command Prompts`

## 创建打包布局映射文件

在包含单一游戏内容文件夹的目录中打开 Microsoft Game Development Kit (GDK) 命令提示符，然后运行以下命令：

`makepkg genmap /f layout.xml /d <Your_Game_Folder>`

## 创建包

### 如何创建包

按照以下步骤创建 `/lk` 加密包：

1. 一次性操作：运行 `makepkg genkey /ekb SECRET_KEY.lekb` 创建 `SECRET_KEY.lekb` 文件。此文件是本地托管密钥数据块 (LEKB)，用于存储加密你的包的稳定内容密钥。请将其存储在需要严格访问控制的安全位置。理想情况下，只有官方构建计算机和账户可访问它。
2. 创建包：运行 `makepkg pack /lk SECRET_KEY.lekb /f layout.xml /d <Your_Game_Folder_Name> /pd <Output_Folder_Name>`。此命令会使用存储在 SECRET\_KEY.lekb 文件中的密钥创建加密的包。

### 关于包加密的重要说明

`makepkg` 的 `/lk` 开关会使用由 `makepkg genkey` 命令创建的稳定（始终相同）密钥来加密包。除了你的游戏包之外，`makepkg /lk` 还会生成格式为 *PackageFullName\_licenseName\_GUID.EKB* 和 *PackageFullName\_licenseName\_GUID.CEKB* 的文件。（注意其中使用了下划线 (\_) 字符。）

在开发工具包测试和主机提交时使用 `/lk` 加密。与测试加密 (`/lt`) 和提交加密 (`/l`) 相比，它具备以下优势：

1. `packageutil compare` 可以生成正确的更新大小估算（不同于 `/l`）。
2. 使用主机和 PC 下载内容更新所用的相同算法，向合作伙伴中心进行安全增量上传。
3. 可以安装到开发工具包上（不同于 `/l`）。
4. 使用安全加密密钥材料，且只能在特定环境中解密（不同于 `/lt`）。

## 测试包安装

使用以下命令测试包安装：

`xbapp install <Your_Package>`

如果你的包使用 Intelligent Delivery Features，请使用 `/i` 选项调用交互式 shell UI 来选择要安装的包 feature，以测试零售最终用户体验。

`xbapp install /i <Your_Package>`

### 关于包安装的重要说明

`xbapp install` 会自动安装将包加载到 XBOX 开发工具包所需的 CEKB 文件。如果你测试的安装场景不是基于工具的安装（如游戏光盘、外部存储、主机到主机传输），可以使用 `xbapp installkey` 命令仅安装 CEKB 文件。有关详细信息，请参阅 [xbapp.exe](/tools/tools-console/commandlinetools/xbapp)。

<Info>
  2021 年 4 月之前的 GDK 生成的 LEKB 文件不会创建 CEKB 文件。要使用新的开发工具包旁加载功能，必须使用 2021 年 4 月或更高版本的 GDK 工具重新创建 LEKB 文件。
</Info>

### 如果你计划为包创建光盘，请参阅以下文章

[创建测试编译光盘](/build/core-features/common/packaging/creating-test-compilation-discs) [创建跨代测试光盘](/build/core-features/common/packaging/creating-cross-gen-test-discs)

## 将包提交到 Microsoft 合作伙伴中心

由于使用 `/lk` 标志对包进行加密，通过前述 makepkg.exe 命令创建的包既可用于测试也可用于提交。上传此包时你也会受益于增量上传。XVC 和 EKB 文件会按常规上传到合作伙伴中心。LEKB 和 CEKB 文件不会上传。

## MicrosoftGame.config 示例

创建名为 MicrosoftGame.config 的文件。在你的游戏内容根目录中使用以下内容，然后移除你不需要项目的注释。有关详细信息，请参阅 [MicrosoftGame.config 参考页](/reference/system/microsoftgameconfig/microsoftgameconfig-schema)。

虽然你可以手动创建 MicrosoftGame.config，但最佳方式是使用 [MicrosoftGame.config 编辑器](/build/core-features/common/game-config/MicrosoftGameConfig-Editor)。

```xml theme={null}
<?xml version="1.0" encoding="utf-8"?>
<Game configVersion="1">
    <!-- Publisher should match the exact value provided in the "Package/Identity/Publisher" field of the Game setup -> Identity section of your product's configuration area in Partner Center.
         Name should match the exact value provided in the "Package/Identity/Name" field of the Game setup -> Identity section of your product's configuration area in Partner Center. -->
    <Identity Name="**REPLACE**"
        Publisher="**REPLACE**"
        Version="1.0.1.0"/>
        <!-- For MSIXVC/MSIXVC2 the fourth digit of the version number is reserved for Microsoft Store use -->

    <!-- These values are found in the Game Setup -> Identity section in your product's configuration area in Partner Center. -->
    <StoreId>**REPLACE WITH STOREID**</StoreId>
    <MSAAppId>**REPLACE WITH MSAAPPID**</MSAAppId>
    <TitleId>**REPLACE WITH TITLEID**</TitleId>

     <!-- Use OverrideDisplayName if you want to display a different title in the shell than the DefaultDisplayName from the ShellVisuals section, or if you need to localize it. 
          Use TargetDeviceFamily to specify what platform your executable is built for (NOTE: Packaging will only allow one TargetDeviceFamily type to be specified to properly build a package. For more information, see the above reference page.) -->
    <ExecutableList>
      <Executable Name="**REPLACE**"
                  Id="Game"
                  OverrideDisplayName="**REPLACE**"
                  TargetDeviceFamily="XboxOne"
                  />
    </ExecutableList>

    <!-- DefaultDisplayName should match the exact value provided in the "Package/Identity/Name" field of the Game setup -> Identity section of your product's configuration area in Partner Center.
         PublisherDisplayName should use the exact value provided in the "Package/Properties/PublisherDisplayName" field of the Game setup -> Identity section of your product's configuration area in Partner Center.-->

    <!-- The following asset sizes apply
         StoreLogo - 100x100
         Square150x150Logo - 150x150
         Square44x44Logo - 44x44
         SplashScreenImage - 1920x1080
    -->
    <ShellVisuals DefaultDisplayName="**REPLACE**" 
                  PublisherDisplayName="**REPLACE**"
                  StoreLogo="StoreLogo.png"
                  Square150x150Logo="Logo.png"
                  Square44x44Logo="SmallLogo.png"
                  Description="**REPLACE**"
                  BackgroundColor="#000040"
                  SplashScreenImage="SplashScreen.png"/>
</Game>
```

## 相关打包文章

[PC 游戏打包入门](/build/core-features/common/packaging/overviews/packaging-getting-started-for-PC) [MicrosoftGame.Config](/build/core-features/common/game-config/MicrosoftGameConfig-toc) [将游戏部署到 XBOX 开发工具包](/home/setup-install/concepts/deployment)


## Related topics

- [使用 MSIXVC 工具打包 PC 游戏入门](/zh-CN/build/core-features/common/packaging/overviews/packaging-getting-started-for-PC.md)
- [包（经典体验）](/zh-CN/publishing/game-publishing/concepts/packages-overview.md)
- [包（Packages）](/zh-CN/publishing/game-publishing/concepts/game-package-management.md)
- [创建游戏包并在合作伙伴中心上传](/zh-CN/publishing/game-publishing/tutorial-xbox-managed/how-to-create-a-package.md)
- [针对 PC 的 MSIXVC2 打包入门](/zh-CN/build/core-features/common/packaging/overviews/packaging-getting-started-for-PC-msixvc2.md)
