I just reinstalled UE5 and and installed the latest version (2022) of visual studio, and then it worked.