Missing modules/Can't generate project files

Yesterday I added a C++ class to my project and when I reopen it, it said missing modules and need to rebuild from source manually. Then I looked up online for some solutions, it said I need to generate project files and rebuild it. However, when I am trying to generate it, there are some errors :

Running D:/UE_5.0/UE_5.0/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.exe -projectfiles -project=“D:/Unreal Projects/我的项目/CryptRaidar.uproject” -game -rocket -progress -log=“D:\Unreal Projects\我的项目/Saved/Logs/UnrealVersionSelector-2022.07.13-12.11.05.log”
Log file: D:\Unreal Projects?ҵ???Ŀ\Saved\Logs\UnrealVersionSelector-2022.07.13-12.11.05.log
Log file: C:\Users\Lenovo\AppData\Local\UnrealBuildTool\Log_GPF.txt
Discovering modules, targets and source code for project…
Compiled assembly file ‘D:\Unreal Projects?ҵ???Ŀ\Intermediate\Build\BuildRules\CryptRaidarModuleRules.dll’ appears to be for a newer CLR version or is otherwise invalid. Unreal Build Tool will try to recompile this assembly now. (Exception: Could not load file or assembly ‘D:\Unreal Projects?ҵ???Ŀ\Intermediate\Build\BuildRules\CryptRaidarModuleRules.dll’. Format of the executable (.exe) or library (.dll) is invalid.)
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidar\CryptRaidar.Build.cs(3,28): error CS0246: The type or namespace name ‘ModuleRules’ could not be found (are you missing a using directive or an assembly reference?)
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidarEditor.Target.cs(3,40): error CS0246: The type or namespace name ‘TargetRules’ could not be found (are you missing a using directive or an assembly reference?)
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidarEditor.Target.cs(5,36): error CS0246: The type or namespace name ‘TargetInfo’ could not be found (are you missing a using directive or an assembly reference?)
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidar\CryptRaidar.Build.cs(5,24): error CS0246: The type or namespace name ‘ReadOnlyTargetRules’ could not be found (are you missing a using directive or an assembly reference?)
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidar\CryptRaidar.Build.cs(5,54): error CS1729: ‘ModuleRules’ does not contain a constructor that takes 1 arguments
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidar\CryptRaidar.Build.cs(7,9): error CS0103: The name ‘PCHUsage’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidar\CryptRaidar.Build.cs(7,20): error CS0103: The name ‘PCHUsageMode’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidar\CryptRaidar.Build.cs(9,9): error CS0103: The name ‘PublicDependencyModuleNames’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidar\CryptRaidar.Build.cs(11,9): error CS0103: The name ‘PublicDependencyModuleNames’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidar\CryptRaidar.Build.cs(13,9): error CS0103: The name ‘PrivateDependencyModuleNames’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidarEditor.Target.cs(5,57): error CS1729: ‘TargetRules’ does not contain a constructor that takes 1 arguments
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidarEditor.Target.cs(7,9): error CS0103: The name ‘Type’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidarEditor.Target.cs(7,16): error CS0103: The name ‘TargetType’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidarEditor.Target.cs(8,9): error CS0103: The name ‘DefaultBuildSettings’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidarEditor.Target.cs(8,32): error CS0103: The name ‘BuildSettingsVersion’ does not exist in the current context
D:\Unreal Projects?ҵ???Ŀ\Source\CryptRaidarEditor.Target.cs(10,9): error CS0103: The name ‘ExtraModuleNames’ does not exist in the current context
ERROR: Expecting to find a type to be declared in a target rules named ‘CryptRaidarTarget’. This type must derive from the ‘TargetRules’ type defined by Unreal Build Tool.

what should I do about it? It’s just driving me crazy :sob:

Hi @PoaCorina! Welcome to the Forums!

What is most likely happening is Visual studios is formatting out the “Using UnrealBuildTool” from your script. Go into VS → Configure Code Cleanup and edit those settings. What you want to remove from the code cleanup options is Remove unnecessary Imports or usings. This should, in theory, solve your problem.

I hope the above solution works for you!

2 Likes