Hey,
I met with same issue and found a easy escape.
Solution 1:
Save and Close your VS2022
Open up your task manager and search for unreal. You will see Unreal Editor and some other unreal supportive applications running on background.
Close them and run your VS and try building now.
Solution 2:
If still the build fails delete “binaries”, “Saved”, “Intermediate” folders from your project folder.
Right click on your UE project file and click “Generate Visual Studio Project files”
You will notice those deleted folders getting created again.
Now open your VS and build solution.