When teaching an undergraduate or graduate course and knowing about some good students, what would be the best approach in inviting them to join a research project? Contacting them directly, or send an email to all students and then select the "good students" that are also interested?
At my institution the selection was two-fold. The professor usually has an open invitation for all students to apply for their lab, but chosen students were known to be approached to raise their interest. This was always done carefully as to don't imply any precedence between students, but not secretly, and almost always orally (not by email or similar). For example, at the project oral defense, the instructor would suggest to the best students to consider applying for their lab.
At least all of my instructors were careful not to "flatter" the students, but only to raise their interest. There is little sense to have a, no matter how brilliant, student working on a project, if they are not interested in the subject.
As an undergrad, I was both approached directly by a prof and responded directly to a job advertisement that a prof posted on a bulletin board near the entrance to our building. Both led to great research experiences for me and no apparent sour grapes or other complaints when my peers found out about my research opportunity. I have also seen a professor simply advertise during class that they had some opportunities available and that those who were interested could see them after class during office hours.
It would be better if you could contact whole class and then select the students who might not only be good, but also very much interested in doing the research. If you think that, someone is good and haven't approached you, you may just ask him/her about it. Also, there's a possibility that you might not know all the students very well, so if you plan to select only the students whom you think who are already good, there's a chance that you might miss out someone who might be better and also more interested. So, I would say to ask the whole group and then decide, depending on the response.