Before knowing the existence of the “Generate VS Project Files” option, I found another way myself that does something similar, and can fix the issue when the former doesn’t work.
First, backup your project!! You can then safely delete the .vs folder, Source folder and the .sln file. Now you should be able to open your .uproject file. Inside the editor, create a new C++ class (also make it public for convenience), close the editor, navigate to the newly generated Source folder, then into the folder with your project name under the Source folder, and replace the Public & Private folders there with the original ones.
And that’s it! Now you shouldn’t encounter any issues when building your project via Visual Studio
Hope this helps!