Visual Studio loses ability to attach to Unity, why?

Benjamin Zach picture Benjamin Zach · Mar 25, 2019 · Viewed 14.1k times · Source

I'm using Visual Studio with Unity. In general in VS I can simply click "Attach to Unity" and it will build the solution and indeed attach to Unity.

Sometimes, however, a project loses the "ability" to do so, what means that suddenly clicking the button will only build the solution and not attach to Unity.

I really would like to know what's happening there as I'm not aware of doing anything that could result in such a behaviour.
There are some parameters that might have an effect:

  • it happens only for some Unity projects: a project is either "infected" or it happens never (on my watch)
  • if it starts happening it will always happen until I reboot the PC (closing VS and Unity is not enough)

Answer

Delta picture Delta · Nov 21, 2020

For me (Unity 2020.x and VS19) this happens quite often. Simply close VS and in Unity > Edit > Preferences > External Tools

Click on "Regenerate project files" (you don't need to check anything else, just click the button)

Start VS again, and it should work as normal.