Visual studio is not to blame here. I compile on the same version of 2022. Your problem most likely is in the compiler versions (MSVC). You probably have a mismatch between the installed version and your unreal engine version.
This is the important part
Make sure your MSVC is in the range as well as Win SDK and .Net
Go into the VS installer into individual components and check that you have the proper MSVC installed in your system.