  A general affine connection has enough degrees of freedom to describe the
classical gravitational and electromagnetic fields in the metric-affine
formulation of gravity. The gravitational field is represented in the
Lagrangian by the symmetric part of the Ricci tensor and the classical
electromagnetic field can be represented by the tensor of homothetic curvature.
The simplest metric-affine Lagrangian that depends on the tensor of homothetic
curvature generates the Einstein-Maxwell equations for a massless vector.
Metric-affine Lagrangians with matter fields depending on the connection are
subject to an unphysical constraint because the symmetrized Ricci tensor is
projectively invariant while matter fields are not. We show that the appearance
of the tensor of homothetic curvature, which is not projectively invariant, in
the Lagrangian replaces this constraint with the Maxwell equations and restores
projective invariance of the total action. We also examine several constraints
on the torsion tensor to show that algebraic constraints on the torsion that
break projective invariance of the connection and impose projective invariance
on the tensor of homothetic curvature replace the massless vector with a
massive vector. We conclude that the metric-affine formulation of gravity
allows for a mechanism that generates masses of vectors, as it happens for
electroweak gauge bosons via spontaneous symmetry breaking.
