  We study two-dimensional U($N$) and SU($N$) gauge theories with a topological
term on arbitrary surfaces. Starting from a lattice formulation we derive the
continuum limit of the action which turns out to be a generalisation of the
heat kernel in the presence of a topological term. In the continuum limit we
can reconstruct the topological information encoded in the theta term. In the
topologically trivial cases the theta term gives only a trivial shift to the
ground state energy but in the topologically nontrivial ones it remains to be
coupled to the dynamics in the continuum. In particular for the U($N$) gauge
group on orientable surfaces it gives rise to a phase transition at $\theta=
\pi$, similar to the ones observed in other models. Using the equivalence of 2d
QCD and a 1d fermion gas on a circle we rewrite our result in the fermionic
language and show that the theta term can be also interpreted as an external
magnetic field imposed on the fermions.
