There are many reasons for and types of neck pain. I've been battling it for 7 years and mostly, the pain wins. I've literally done everything short of surgery. RF ablation and intralaminar injections reduce pain for me. Riding a recumbent reduces neck pain for me. Reducing miles per week helps. Icing after rides helps. Narcotics help a little. Anti-inflammatories do not help me.
(I am assuming you have been fit properly or riding long enough to know how to position yourself on the bike...?)