
During the Mexican War he headed the construction of United States defenses at Tampico, and was the one who surveyed the lands around Mexico City before the United States forces captured it. His services in Mexico earned him the Regular Army brevet of Major.
He served as the Wets Point Superintendent from 1856 to 1858, and was promoted to full-rank Major in 1858. Upon the outbreak of the Civil War he first served as Chief Engineer for the Department of Washington, then as Brigadier General Irwin McDowell's top Engineer during the July 1861 First Bull Run Campaign, where his reconnaissance influenced General McDowell's tactics. Promoted to Brigadier General, US Volunteers, he served as Chief Engineer of the Army of the Potomac, serving under Major General George B. McClellan during the 1862 Peninsular Campaign. In that capacity he directed the Siege of Yorktown, fought at the Battle of Williamsburg, and scouted and selected the fields where the Battles of Gaines Mill, White Oak Swamp and Malvern Hill were fought. Re-assigned Chief Engineer of Washington, he served in the Capital until January 1864, when he was appointed Chief Engineers of the Union Army, filling the vacancy caused by the death of General Joseph Totten. In this role he was on the Staff of Union Army commander Lieutenant General Ulysses S. Grant, with whom he served in the field in the 1864 Overland Campaign, and the ensuing Siege and Capitulation of Petersburg, Virginia. General Barnard was present in Appomattox when the Confederate Army of Northern Virginia surrendered. He had been promoted to Lieutenant Colonel of Engineers in March 1863, and finished the war with brevets of Major General, US Volunteers and Major General, US Regular Army for "gallant and meritorious services in the field".In 1862 he wrote one of the first technical treatments of a Civil War battle when he published "The Confederate States of American at the Battle of Bull Run", only a year after it had been fought. General Barnard died in 1881 in Detroit, Michigan, and his interred in the town of his birth.