We give the tangent space formulation for the BRST transformations of
the Yang-Mills gauge field in the presence of gravity with torsion. Us
ing Sorella's operator delta, we solve the BRST consistency condition
corresponding to invariant Chern-Simons terms and gauge anomalies. Con
trary to the case of pure Yang-Mills gauge theory, we have a closed al
gebra between the operator delta, the exterior spacetime derivative an
d the BRST operator. Due to this fact, we can present an integrated pa
rameter formula for the solution of the local BRST cohomology correspo
nding to the gauge anomalies.