While answer to your question needs more detail, but in general the answer looks like this:
Starting PhD is different at different universities. At many universities, faculty members receive applications from the PhD applicants and evaluate individually. However, at other universities mostly in the US, the application is evaluated by a committee.
In the first case, certainly, the best way to start is to initiate a communication with potential PhD supervisors by sending an email -as you said- along with your CV, academic history, SoP, and research proposal (proposal is not needed in US, but should not be a problem if you send). However, I think it may not really work if you ask them for assignment (maybe it works in some universities that I don't know).
One thing I noticed when I was searching for my PhD is that many supervisors write some notes on their pages and provide instructions for potential students to follow. If you simply don't follow them you won't be able to get position from them. Try to read their pages as carefully as you can.
I admit that there is tension in getting a PhD position. But it is all right and should be okay. Some guidelines may help you figure it our.
In general, to successfully secure a PhD position, you need certain qualifications and certificates listed as following:
- Bachelor degree in relevant course with high GPA/CGPA (this is must)
- Master degree in relevant course with high GPA/CPGA (This is not really a MUST-have requirement, since many universities offer PhD without having Master).
- English Proficiency certificate (for English speaking countries) if you English is not your native language.
- 2/3 reference letters in your favor (no wonder).
- GRE for US-based universities.
- Money to pay tuition fee (supervisors consider this as well. If you need financial assistance you should be really good compare to others).
That's all REQUIREMENTS. But, they are not sufficient to convince a potential academician to offer you a position, especially paid positions which are very competitive. If you want to enhance your chance, I think in CS you need the following qualifications:
- Good quality publication(s) in good publishing venues (top ranked conference and journals)
- Research experience (It may be true that Master by research graduates have better chance here).
- Working experience in relevant areas
- Teaching experience
- Professional certificates from well-known organizations like Microsoft, and Oracle.
- Volunteer jobs in the society (I heard a lot about it)
- Academic or professional Awards like best student, best thesis, and best paper award.
- GRE and SAT certificates
- Intellectual properties (patents)
But, I think the most important thing is the first impression that you make using your first email, CV, SoP, statement of research and so on. If they look professional and neat, it attracts potential supervisor's attention and will evaluate your application optimistically.
Don't give up. You have to find the RIGHT supervisor, at the RIGHT university, at the RIGHT time, using the RIGHT channel. Keep trying and you will succeed.