【UE5】Visual Studioプロジェクト作成しようとするとエラーが出るときの対処方法

はじめに

Visual studioプロジェクト(.sln)作成しようとするとエラーがでたので対処法をメモ

環境はUE5.0.3 、Visual studio2019をインストール済みです

エラーメッセージはこんな感じ

Running C:/Program Files (x86)/Epic Games/UE_5.0/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.exe -projectfiles -project="D:/UE/Appendix E/PaperNinja.uproject" -game -rocket -progress A fatal error occurred. The required library hostfxr.dll could not be found. If this is a self-contained application, that library should exist in [C:\Program Files (x86)\Epic Games\UE_5.0\Engine\Binaries\DotNET\UnrealBuildTool]. If this is a framework-dependent application, install the runtime in the global location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation].

The .NET Core runtime can be found at: - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=win10-x64

対処方法

1 hostfxr.dllをコピー

「hostfxr.dll」ファイルをコピーします

hostfxr.dllは"C:\Program Files\Epic Games\UE_5.0EA\Engine\Binaries\ThirdParty\DotNet\Windows\host\fxr\3.1.9"にあります。

コピーした「hostfxr.dll」をエラーメッセージに書いてある 「C:\Program Files\Epic Games\UE_5.0EA\Engine\Binaries\DotNET\AutomationTool」に置きます

2 .NETをインストール

hostfxr.dllをコピーした後にVisual Studioプロジェクト作成しようとすると以下のエラーが出ます

内容としては.NET Core 3.1をインストールを求められています

Running C:/Program Files (x86)/Epic Games/UE_5.0/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.exe -projectfiles -project="D:/UE/study/02 Starter Kit Overview/BlueprintsToCpp/BlueprintsToCpp.uproject" -game -rocket -progress It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '3.1.0' was not found. - No frameworks were found.

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at: - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.1.0&arch=x64&rid=win10-x64

エラーメッセージに記載されているURLか下記URLから.NET Core 3.1をインストール出来るのでインストールします

dotnet.microsoft.com

3 C++によるゲーム開発をインストール

人によってはNETをインストールした段階でVisual Studioプロジェクト作成出来ますが自分は下記エラーが出ました。

Running C:/Program Files (x86)/Epic Games/UE_5.0/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.exe -projectfiles -project="C:/UE/Appendix E/PaperNinja.uproject" -game -rocket -progress -log="C:\UE\Appendix E/Saved/Logs/UnrealVersionSelector-2022.10.21-15.41.43.log" Log file: C:\UE\Appendix E\Saved\Logs\UnrealVersionSelector-2022.10.21-15.41.43.log Log file: C:\Users\otake\AppData\Local\UnrealBuildTool\Log_GPF.txt

Some Platforms were skipped due to invalid SDK setup: Win64, IOS, Android, Linux, LinuxArm64. See the log file for detailed information

Discovering modules, targets and source code for project... WARNING: Visual Studio C++ 2019 installation not found - ignoring preferred project file format. ERROR: Visual Studio 2019 x64 must be installed in order to build this target.

原因としてはVisual Studio2019はインストールしてたがC++によるゲーム開発をインストールしてなかったみたいです

下記を参考にC++によるゲーム開発をインストールします。これでVisual Studioプロジェクト作成出来るようになります

https://learn.microsoft.com/ja-jp/visualstudio/install/modify-visual-studio?view=vs-2022

※下記3つにチェックを入れる必要があります

C++ プロファイリング ツール

C++ AddressSanitizer (オプション)

Windows 10 SDK (10.0.18362 以降)

4 パスの修正

ここまできてもVisual Studioプロジェクトを生成できない、またはVisual Studioプロジェクトはできたけど正常に開けないパターンがあります

Visual Studioプロジェクトを生成できてないかたはTool→新しいc++クラスを作成で適当にクラスを作成するとVisual Studioプロジェクトは生成できます。

ですがUE5からVisual Studioプロジェクトを開こうとすると「ソリューションを開けません」のエラーメッセージがでます。

この場合はエクスプローラーから.slnを選択してVisual Studioプロジェクトを開いてみます。

上記の表示をみるとプロジェクトがうまくロード出来てないことが考えられます。試しにUE5を右クリックして再度プロジェクトを読み込むを選択すると下記エラーメッセージが出ました。

Microsoft.Cpp.Default.props" が見つかりませんでした。

調べた感じMSBuild関連のパス設定がうまくいってないようです。 修正方法は環境によりますが自分は環境変数「VCTargetsPath」を削除してPC再起動で正常にプロジェクトを読み込めるようになりました。

他の修正方法としては下記のやり方があります

qiita.com

EX Visual Studioの設定

Visual Studioプロジェクトはいくつか設定しないといけないことがあるこの下記URL参考に設定すると良いです

参考

note.com