Deleting the hidden .vs
folder + visual studio project and solution files didn't work for me.
Restarting windows-explorer allowed me to attach the Visual Studio. (See variant 3)
variant 1:
But when I opened Task Manager and went into Details tab, I saw 3 Unity.exe
and 6 Unity Hub.exe
.
I ended all of these tasks, and ensured the visual studio files mentioned above are deleted.
Restarted unity, clicked on one of my scripts, it launched visual studio, regenerating its files, and then debugger was attaching again!
So check if there are several exes running.
variant 2:
I noticed that my other unity-projects work just fine, VisualStudio attaches to them correctly. Therefore tried this and it worked:
- I closed unity, visual studio, UnityHub.
- did what's described in variant 1
- changed the name of the unity project's directory.
- deleted the .vs folder + all vs solution and vs project files.
- Opened UnityHub, removed the old project from the list, and re-added a new one (from this modified directory).
- It opened, I clicked on one of my scripts, Visual Studio opened and was able to attach.
So the path to unity project is important and is probably cached somewhere. So if visual studio doesn't attach, try changing the path to your unity-project.
in my case it was simply:
C:\myFiles\myFancyUnityProject\
renamed to
C:\myFiles\myFancyUnityProject-1\
variant 3:
Noticed that I couldn't rename the folder as if something in Windows was holding it. So I opened Task Manager, went into Details tab. Found explorer.exe
right clicked and ended the task.
Then clicked File->Run new Task and typed explorer
.
Restarting windows-explorer this way actually allowed me to attach the Visual Studio. And I didn't have to delete the .vs folder or any solution files. But I still restarted windows and Visual Studio and terminated stuff as in variant 1.