Toolchain Error Generating Project Files for VS 2022 (UE 5.1)

I just finished building Unreal from source, but I didn’t realize that I had accidentally generated project files for VS 2019 instead of 2022. So I updated BuildConfiguration.xml to use VisualStudio2022 (as it says if you do -2022) and tried to rerun GenerateProjectFiles.bat, but no matter what I do I get the following error or something similar:

Discovering modules, targets and source code for project...
Binding IntelliSense data...
Binding IntelliSense data... 100%
Writing project files...
Available x64 toolchains (4):
 * C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32124
    (Family=14.35.32124, FamilyRank=2, Version=14.35.32124, Is64Bit=True, Preview=True, Architecture=x64, Error=False)
 * C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933
    (Family=14.34.31933, FamilyRank=2, Version=14.34.31937, Is64Bit=True, Preview=True, Architecture=x64, Error=False)
 * C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629
    (Family=14.33.31629, FamilyRank=1, Version=14.33.31631, Is64Bit=True, Preview=True, Architecture=x64, Error=False)
 * C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705
    (Family=14.30.30705, FamilyRank=2, Version=14.30.30711, Is64Bit=True, Preview=True, Architecture=x64, Error=False)
Writing project files... 0%
Unable to find valid latest C++ toolchain for VisualStudio2022 x64

I’ve tried changing the WindowsPlatform.CompilerVersion attribute in BuildConfiguration.xml, but if I enter Latest, Preview, or any of the version numbers from above, i get that exact error. If I enter a non-existent version (for example 987354) it changes to Unable to find valid 987354 C++ toolchain for VisualStudio2022 x64, so it is at least recognizing my configuration.

There is this thread of someone with a similar issue:
https://forums.unrealengine.com/t/unable-to-generate-vs-project-files-for-5-1/717750
The difference is that is says exactly which version its looking for and it worked after he installed it. I have the specified version installed and its giving me this error. He’s also just trying to generate project files for a game, but I’m trying to regenerate project files for the source.

I’m sure there’s a simple solution, something I need to delete, something to install, a setting or argument to change, but I cannot figure it out.

Extra info:
I’m using Visual Studio 17.5.0 Preview 2.0
You can see the versions of the MSVC x86/x64 toolchain I have installed above
Using Unreal Engine 5.1 from the Github release branch from January 13

1 Like

Not going to work if you built with another version or who knows, packages are picky too and plugins, if you have compiled something with 2019 in unreal , a cpp and launch it with unreal that has 2022 (same version of unreal), it will say when you do that it’s built with a different version even if you compiled with the same version of unreal, and that the file needs to be rebuilt. It thinks you have another unreal version. It only works if you have same version of unreal and same compiler version - build tools. If any of these are different I get built with another version. This is for precompiled stuff, binaries, it never works and I have to rebuild the CPP.

I found what was causing it and found a work around, but it feels like a bug and I’m not sure what the side effects of the work around might be.

The issue is that I don’t have any non-preview toolchains. I tried to install one that was non-preview, but they all said preview after I installed them.
What was happening is this one line in the UnrealBuildTool source code in Engine\Platforms\Hololens\Source\Programs\UnrealBuildTool\HoloLensProjectGenerator.cs line 87:

DirectoryReference? PlatformWinMDLocation = HoloLensPlatform.GetCppCXMetadataLocation(Compiler, "Latest", WindowsArchitecture.x64, Logger);

The "Latest" argument does the same as using Latest for the CompilerVersion: it excludes preview toolchains. Because it was hardcoded, it would always fail if only preview toolchains are available.

So to “fix” it, I simply changed that "Latest" to "Preview".

5 Likes