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:
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.