I was referred here from the casual Microsoft forum: https://answers.microsoft.com/en-us/windows/forum/windows_11-hardware/visual-studio-cant-locate-installer-or-net/af4406ec-88ea-4acf-beed-27e0428ba347?messageId=6d100f88-fc38-4f8a-8f45-a17e52d81f81
So I'm trying to work on a new project in Unity and using Visual Studio as my code editor. When opening Visual Studio through double-clicking a script in Unity, I get the error "Target framework not installed": The C# project Assembly-CSharp targets a version of .NET Framework that is not installed. While you can change your target framework at any time, for stability and security we recommend that you move to a recent supported release.
This is already weird since the project is configured to use .NET Framework 4.8, but it suggests updating the target to .NET Framework 4.8, or to download version 4.7.1, either way both of these frameworks were installed through the Visual Vtudio installer.
I've tried both options and both lead to Visual Studio opening with "Assembly-CSharp (load failed)" appearing in the solution explorer. If I try to right click the project and choosing "Reload Project", I once again get the error "Target framework not installed" with the same description, except now it suggests downloading .NET Framework 4.8, which again, is already installed both manually and through the Visual Studio Installer.
At this point I wondered if Visual Studio was connected to the installer, and sure enough going to Tools -> Get Tools and Features... results in the error "Unable to locate Visual Studio Installer".
So there's now two installations that Visual Studio won't detect, but I can detect manually and verify that the files exist in the place where I expect them to.
Finally I went to Apps & Features in the windows 11 start menu, and it seems that the problem stems from windows itself not being able to find installations, as when I click Visual Studio Community 2022 -> modify, I get the error "Windows cannot find 'D:\Microsoft Visual Studio\Installer\setup.exe'. The installer itself is installed in drive C:, so I suspect the problem might be that both Windows and Visual Studio are looking for programs in the wrong drive.
How can I resolve these issues? Would changing where Windows looks for programs help? If so, how can I do that?