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

# PC ゲーム開発向け Visual Studio プロジェクト テンプレート

> PC ゲーム開発向け Visual Studio プロジェクト テンプレート

このトピックでは、Visual Studio で利用可能な Windows PC ゲームのプロジェクト テンプレートについて説明します。

## プロジェクト テンプレート

Microsoft Game Development Kit (GDK) は、次の Visual Studio C++ プロジェクト テンプレートをインストールします。

* **Direct3D 12 Desktop Game (Classic):** 「標準」の x64 MSBuild プラットフォームで、Direct3D 12 と C++ を使用する Windows ゲーム用プロジェクト。
* **Direct3D 12 Desktop Game:** Gaming.Desktop.x64 MSBuild カスタム プラットフォームで、Direct3D 12 と C++ を使用する Windows ゲーム用プロジェクト。
* **Direct3D 12 Desktop Game Makefile:** 外部ビルド システムを使用して Direct3D 12 と C++ を使用する Windows ゲーム用プロジェクト。
* **Desktop Static Library:** Gaming.Desktop.x64 MSBuild カスタム プラットフォームで作成する Windows 静的ライブラリのプロジェクト。
* **Desktop DLL:** Gaming.Desktop.x64 MSBuild カスタム プラットフォームで作成する Windows ダイナミック リンク ライブラリのプロジェクト。

### スタンドアロン テンプレート

デスクトップおよびハンドヘルド開発でインストール済みの GDK テンプレートを使用する代わりに、[vc Package Manager](https://aka.ms/vcpkg) を使用してパッケージ化された *Microsoft GDK* や *DirectX 12 Agility SDK* などを追加する、完全にスタンドアロンなプロジェクト テンプレートがあります。これは、Microsoft Store および XBOX PC アプリで出荷するためのベースラインとして使用できます。このパッケージには MSBuild と CMake の両方のプロジェクト テンプレートが含まれており、Visual Studio 2022 v17.6 以降が必要です。

[Visual Studio Marketplace](https://aka.ms/gdktemplates) を参照してください。

## Microsoft Game Development Kit (GDK) プロジェクト テンプレートの検索

Microsoft Game Development Kit (GDK) テンプレートは、Visual Studio 2019 または Visual Studio 2022 の **\[新しいプロジェクトの作成]** ダイアログ ボックスで検索およびフィルターすることで見つけられます。次のスクリーンショットに示すように、**言語:C++**、**プラットフォーム:Windows**、**プロジェクトの種類:Games** でフィルターすると、Microsoft Game Development Kit (GDK) テンプレートを見つけることができます。

<img src="https://mintcdn.com/microsoft-4404708b/6TXzXmujKayly5Sf/images/gdk/tools/vs_2019_pc_templates.png?fit=max&auto=format&n=6TXzXmujKayly5Sf&q=85&s=69a6e437793926b85bda150574bff5f3" alt="Windows PC ゲーム テンプレートを検索するための、Visual Studio 2019 の [新しいプロジェクトの作成] ダイアログ ボックスのスクリーンショット" width="903" height="628" data-path="images/gdk/tools/vs_2019_pc_templates.png" />

## Gaming.Desktop.x64 プラットフォーム、msbuild ファイル、およびプロパティ

Microsoft Game Development Kit (GDK) は、Windows PC ゲーム開発で使用する Gaming.Desktop.x64 という名前の msbuild プラットフォームを定義します。Gaming.Desktop.x64 には、必須のプリプロセッサ ディレクティブ (`_GAMING_DESKTOP` など) を定義する msbuild プロパティおよびターゲット ファイルのセットが含まれており、ゲームをビルドしたときに、たとえば拡張ライブラリ、インクルード ファイル、およびライブラリが *C:\Program Files (x86)\Microsoft GDK\edition\GRDK* 配下で正しく見つかるようにパスをセットアップします。Gaming.Desktop.x64 プラットフォームで定義される msbuild プロパティおよびターゲットの具体的な詳細については、「[Microsoft Game Development Kit をインストールせずにプロジェクトを構成する](/build/console-features/build-without-install/project-configuration-withoutinstall)」を参照してください。

## Microsoft Game Development Kit (GDK) での x64 プラットフォームの使用

カスタムの Gaming.Desktop.x64 MSBuild プラットフォームを使用せずに PC をターゲットにする場合、プロジェクト ファイルで必要なすべての機能を実装する必要があります。

* 「サイド バイ サイド」インストールをサポートするには、プロジェクトが適切なエディションを選択する必要があります。これは *Globals* セクションで設定するプロパティによって実現できます。

```xml theme={null}
<PropertyGroup Label="Globals">
...
  <GDKPCEditionPath>$(GRDKLatest)</GDKPCEditionPath>
</PropertyGroup>
```

`GRDKLatest` 環境変数を使用すると、既定で開発 PC にインストールされている最新のエディションになり、その形式は **C:\Program Files (x86)\Microsoft GDK\<edition>\GRDK\\** になります。

> ビルド設定の残りの部分では **GDKPCEditionPath** プロパティを使用します。プロジェクト ファイルの残りの部分で `GRDKLatest` をプロパティとして直接使用することは推奨しません。これは、新しいリリースの試用、更新の管理、問題の再現などが困難になるためです。ビルド プロセスを制御するためにカスタム .props ファイルを使用している場合は、各プロジェクト ファイルではなくそこに `GDKPCEditionPath` を配置してください。また、このプロパティは MSBuild の規約を満たすために末尾のスラッシュが必要である点にも注意してください。

VS 2019 の場合は、ツールの x64 ネイティブ バージョンを必ず使用してください。VS 2022 ではこれが既定であるため、オプションです。

```xml theme={null}
<PropertyGroup Label="Globals">
...
  <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
```

* 必要な Microsoft Game Development Kit (GDK) 拡張ライブラリには、適切な include/lib パスと必要な再頒布 DLL を含める必要があります。これは、vcxproj ファイルの *ExtensionSettings* インポートを変更することで実現できます。

**Microsoft GDK (2024 年 10 月) 以降:**

```xml theme={null}
<ImportGroup Label="ExtensionSettings">
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\Xbox.Services.API.C\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\Xbox.XCurl.API\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\Xbox.LibHttpClient\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\Xbox.Game.Chat.2.Cpp.API\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\PlayFab.Multiplayer.Cpp\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\PlayFab.Party.Cpp\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\PlayFab.PartyXboxLive.Cpp\ExtensionLibrary.props" />
</ImportGroup>
```

**Microsoft GDK (2024 年 6 月) 以前:**

```xml theme={null}
<ImportGroup Label="ExtensionSettings">
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\Xbox.Services.API.C\DesignTime\CommonConfiguration\Neutral\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\Xbox.XCurl.API\DesignTime\CommonConfiguration\Neutral\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\Xbox.LibHttpClient\DesignTime\CommonConfiguration\Neutral\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\Xbox.Game.Chat.2.Cpp.API\DesignTime\CommonConfiguration\Neutral\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\PlayFab.Multiplayer.Cpp\DesignTime\CommonConfiguration\Neutral\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\PlayFab.Party.Cpp\DesignTime\CommonConfiguration\Neutral\ExtensionLibrary.props" />
    <Import Project="$(GDKPCEditionPath)ExtensionLibraries\PlayFab.PartyXboxLive.Cpp\DesignTime\CommonConfiguration\Neutral\ExtensionLibrary.props" />
</ImportGroup>
```

* VC++ ディレクトリのプロパティ **ExecutablePath**、**IncludePath**、**LibraryPath** を更新して、Microsoft Game Development Kit (GDK) のパスを含める必要があります。

```xml theme={null}
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  <ExecutablePath>$(GameDK)bin;$(ExecutablePath)</ExecutablePath>
  <IncludePath>$(GDKPCEditionPath)GameKit\Include;$(Console_SdkIncludeRoot);$(IncludePath);</IncludePath>
  <LibraryPath>$(GDKPCEditionPath)GameKit\lib\amd64;$(Console_SdkLibPath);$(LibraryPath)</LibraryPath>
</PropertyGroup>
```

```xml theme={null}
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  <ExecutablePath>$(GameDK)bin;$(ExecutablePath)</ExecutablePath>
  <IncludePath>$(GDKPCEditionPath)GameKit\Include;$(Console_SdkIncludeRoot);$(IncludePath);</IncludePath>
  <LibraryPath>$(GDKPCEditionPath)GameKit\lib\amd64;$(Console_SdkLibPath);$(LibraryPath)</LibraryPath>
</PropertyGroup>
```

実行可能ファイルのパスについては、これは「サイド バイ サイド」ではないため、`GameDK` 環境変数を直接使用しています。必要に応じて、これもカスタム .props ファイルのプロパティとしてオーバーライドできます。

**Console\_SdkIncludeRoot** および **Console\_SdkLibPath** プロパティは、x64 PC と XBOX の両方に互換性のある Microsoft Game Development Kit (GDK) *ExtensionLibrary.props* によって提供されます。

* プラットフォームの *ItemDefinitionGroups* では、ライブラリまたはその他のミドルウェアを使用する際に Gaming.Desktop.x64 との一貫性を保つために、プリプロセッサ定義に `_GAMING_DESKTOP` を必ず追加してください。

```xml theme={null}
 <PreprocessorDefinitions>_GAMING_DESKTOP;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
```

```xml theme={null}
<PreprocessorDefinitions>_GAMING_DESKTOP;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
```

* 同じく *ItemDefinitionGroups* で、追加のライブラリ依存関係に次のライブラリを追加します。具体的には、GameRuntime 用の `xgameruntime.lib` と、PC 上の GameInput 用の `gameinput.lib` です。

```xml theme={null}
<AdditionalDependencies>xgameruntime.lib;gameinput.lib;d3d12.lib;dxgi.lib;dxguid.lib;uuid.lib;kernel32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
```

* 最後に必要な要素は、ソースの **MicrosoftGameConfig.mgc** ファイルを、ビルド出力で必要となる **MicrosoftGame.config** に変換することです。これはビルド カスタマイズとして実装できます。

```xml theme={null}
<CustomBuild Include="MicrosoftGameConfig.mgc">
  <Command>copy %(Identity) "$(OutDir)MicrosoftGame.config"
makepkg.exe localize /d "$(OutDir)" /pd "$(OutDir)" /gc "%(Identity)"</Command>
  <Message>MGC Compile</Message>
  <Outputs>$(OutDir)MicrosoftGame.config</Outputs>
</CustomBuild>
```

**MicrosoftGame.config** は、有効となるために必要なロゴ アセットも必要となります。これはファイルのコピーで実現できます。

```xml theme={null}
<ItemGroup>
  <CopyFileToFolders Include="GraphicsLogo.png" />
  <CopyFileToFolders Include="LargeLogo.png" />
  <CopyFileToFolders Include="SmallLogo.png" />
  <CopyFileToFolders Include="SplashScreen.png" />
  <CopyFileToFolders Include="StoreLogo.png" />
</ItemGroup>
```

> *Direct3D 12 Desktop Game (Classic)* テンプレートからプロジェクトを作成し、上記の設定およびその他の推奨事項を確認してください。

## 関連項目

[Visual Studio (PC ゲーム開発向け)](/tools/tools-pc/visualstudio/gr-visualstudio-toc)


## Related topics

- [Visual Studio (目次)](/ja-jp/tools/tools-pc/visualstudio/gr-visualstudio-toc.md)
- [XBOX 開発向けの Visual Studio プロジェクト テンプレート](/ja-jp/tools/tools-console/visualstudio/durango-visual-studio-templates.md)
- [GDK プロジェクト テンプレートで新しい PC タイトルを開始する](/ja-jp/build/gdk-and-engines/guides/gdk-project-templates.md)
- [PC ゲーム開発向け Visual Studio プロパティ](/ja-jp/tools/tools-pc/visualstudio/gr-vs-property-pages.md)
- [新しい GDK タイトルを開発する](/ja-jp/home/build-first-title/developing-new-titles.md)
