The effects of cosmic rays on the formation of Milky Way-mass galaxies in a cosmological context