One reason this can happen is being on the wrong signing tab:
under "signing & capabilities" tab there are three sub-tabs:
"all", "debug", and "release"
It recently happened to me that I kept getting this error and the reason was that I only had a team selected on the "release" tab (which is what I was looking at for some reason) but not on the "debug" tab, which is what I was trying to use. I really wish there were no sub-tabs here and it just always showed the all tab. such a dumb way to waste hours of my time. typical apple developer experience.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: