Really weird behavior when generating project files

I kept on getting a message that said “Couldn’t find target rules file for target ‘MyProjectName’” when I tried to generate visual studio files. I attempted reinstalling UE4 and VS and still got this bug. The weird part was, that when I copied the project to another folder and tried again the code would generate.

I’m not sure if this is a bug, and I have found a workaround, but this is still really weird to me. Here is a video of the phenomenon-

Can anyone explain this?