> ## 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.

# GDK 可下载内容 (DLC) 包

> Microsoft 游戏开发工具包可下载内容(DLC)包

Microsoft 游戏开发工具包(GDK)的可下载内容(DLC)包是与主游戏分开的独立包。DLC 包会独立于游戏其余部分单独出售和下载,或作为购买捆绑包的一部分。

创建、发布和使用 DLC 包的流程在概念上与 XBOX One 主机游戏相同,但部分打包文件格式和运行时 API 已更新,使用起来更为简单。

DLC 包在 PC 上使用相同的打包结构支持,并且在主机和 PC 上使用相同的运行时 API 进行访问。

对于 XBOX Series X|S 与 XBOX One 主机,可以生成一个可用于两种平台的 DLC 包桩文件(stub)。如果 DLC 包中包含真正的内容差异,请使用 `TargetDeviceFamilyForDLC` 元素生成特定平台的 DLC 包。

## 设置主包的标识

1. 在主游戏产品的 **Game Setup** 页面中查找主应用包的 Store ID(12 个字符的字母数字字符串)。(示例:9PNX12345AAA)

2. 将 `StoreId` 元素添加到主包的 MicrosoftGame.config 文件中。

```xml theme={null}
<?xml version="1.0" encoding="utf-8"?>
<Game configVersion="1">
    <!-- Content omitted for brevity. -->
    <StoreId>**REPLACE WITH STOREID**</StoreId>
</Game>
```

## 创建 DLC 包

1. 在 Partner Center 中的主产品下,通过 **Add-Ons** 菜单创建你的 DLC 包附加项。

2. 将所有 DLC 包内容放入单个目录。

3. 在与 DLC 包内容相同的目录中,使用下面的示例数据创建一个 MicrosoftGame.config 文件。

4. 在 `TargetDeviceFamilyForDLC` 字段中指定该 DLC 包所面向的 **Target Device Family**。允许的值为 XBOX One、XBOX Series X|S 或 PC。对于 XBOX One 和 XBOX Series X|S 是必需的;对于 PC 而言,只要在使用 makepkg.exe 生成 DLC .MSIXVC 文件时使用了 `/pc` 标志,则为可选。

5. 在 Partner Center 的 **Game Setup** 页面中查找主应用包的 **Package/Identity/Name** 字段,然后将该 Identity Name 填入 `MainPackageDependency` 字段。例如,MyPackageName

6. 从 Partner Center 中查找你的附加项/DLC 包的 Store ID(12 个字符的字母数字字符串),然后将其放入 `StoreId` 字段,如下所示。

7. 在主游戏产品的 **Game Setup** 页面中查找主应用包的 Store ID(12 个字符的字母数字字符串)。将其放入 `AllowedProduct` 字段中,如下所示。例如,9PNX12345AAA

```xml theme={null}
<?xml version="1.0" encoding="utf-8"?>
<Game configVersion="1">
    <Identity Name="**REPLACE**"
        Publisher="**REPLACE**"
        Version="1.0.0.0"/>
    <ShellVisuals DefaultDisplayName="**REPLACE**"
                  PublisherDisplayName="**REPLACE**"
                  StoreLogo="Storelogo.png"
                  Square150x150Logo="Logo.png"
                  Square44x44Logo="SmallLog.png"
                  Description="**REPLACE**"
                  BackgroundColor="#000040"
                  SplashScreenImage="SplashScreen.png"/>
    <StoreId>**REPLACE WITH STOREID OF ADD-ON / DLC**</StoreId>
    <TargetDeviceFamilyForDLC>**REPLACE**</TargetDeviceFamilyForDLC>
    <AllowedProducts>
      <AllowedProduct>**REPLACE WITH STOREID OF BASE GAME**</AllowedProduct>
    </AllowedProducts>

<!-- The Desktop Registration section is for PC only. -->
    <DesktopRegistration>
      <MainPackageDependency Name="**REPLACE_WITH_IDENTITY_OF_PARENT_PRODUCT**" />
      <ProcessorArchitecture>x64</ProcessorArchitecture>
    </DesktopRegistration>
</Game>
```

8. 在包含单个游戏内容文件夹的目录中,打开 Microsoft 游戏开发工具包(GDK)命令提示符,然后运行以下命令。

`MakePkg genmap /f layout.xml /d <Your_dlc_folder>`

9. 如果你在为 PC 创建 DLC,请使用以下命令。

`MakePkg pack /f layout.xml /lt /d <Your_dlc_folder_name> /pc /pd <Output_Folder_Name>`

10. 如果你在为主机创建 DLC,请使用以下命令。

`MakePkg pack /f layout.xml /lt /d <Your_dlc_folder_name> /pd <Output_Folder_Name>`

在早期的 SDK 中,你会在命令行上使用 `/ProductID` 标志传递主游戏的 Product ID GUID。
在使用 MicrosoftGame.Config 模型配置 DLC 包关系时,请不要使用 `/ProductID` 参数。MakePkg 会根据你 MicrosoftGame.config 文件中列出的 StoreID 自动将适当的信息放入你的包中。

## 在游戏运行时访问 DLC 包

在 DLC 包中使用内容的基本步骤如下。

1. [枚举包](/reference/system/xpackage/functions/xpackageenumeratepackages)
2. [检查目标包的有效用户许可证](https://learn.microsoft.com/build/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)
3. 从枚举结果中获取 `packageIdentifier`,并将其传递给 [XPackageMount](/reference/system/xpackage/functions/xpackagemount) API。

在 XBOX Series X|S 主机上,除非你在 MicrosoftGame.config 中为 `DlcCompatibility` 字段指定 `XboxOne`,否则只能使用 `TargetDeviceFamilyForDLC` 为 XBOX Series X|S 的 DLC 包:

```xml theme={null}
    <VirtualMachine>
        <DlcCompatibility>XboxOne</DlcCompatibility>
    </VirtualMachine>
```

XBOX Series X|S DLC 只能安装在快速存储上,而 XBOX One DLC 没有此类限制,因此在选择加入之前请务必考虑这一点。

## 部署和测试 DLC 包

请务必在安装 DLC 包之前安装主游戏包。

对于 XBOX 主机,使用以下命令安装 DLC 包。
`xbapp install <Your_DLC_Package.xvc>`

对于 PC,使用以下命令安装 DLC 包。
`wdapp install <Your_DLC_Package.msixvc>`

DLC 内容也可以从包含松散文件的目录注册,并且可以使用从 Microsoft Store 下载的包进行测试。

有关详细信息,请参见 [Manage and license downloadable content](https://learn.microsoft.com/build/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)。

## 参考 API 文档

* [XPackage(API 内容)](/reference/system/xpackage/xpackage_members)
  * Functions
    * [xpackageenumeratepackages](/reference/system/xpackage/functions/xpackageenumeratepackages)
    * [XPackageMount](/reference/system/xpackage/functions/xpackagemount)


## Related topics

- [[DEPRECATED] XPackageMount](/zh-CN/reference/system/xpackage/functions/xpackagemount.md)
- [管理并授权可下载内容 (DLC)](/zh-CN/publishing/xstore-commerce/xstore-dlc.md)
- [认证 PC BVT 指南](/zh-CN/publishing/game-publishing/concepts/certification/certification-pc-bvt-guide.md)
- [跨网络多人游戏实现示例:MMO](/zh-CN/services/xbox-services/multiplayer/concepts/live-console-xr007-mmo-example.md)
- [认证主机 BVT 指南](/zh-CN/publishing/game-publishing/concepts/certification/certification-console-bvt-guide.md)
