Guerra de las Naranjas
Already with the rank of colonel, in March 1800 he was made governor and captain-general of Pará, but did not set out for Brazil. In the War of the Oranges of the following year, at Alentejo, he served as quartermaster-general (chief of staff) to General Forbes. In 1806 he was promoted to brigadier and made inspector general of the army. On the royal family's flight to the Portuguese colony of Brazil in 1807, he was made deputy secretary of the government, to if necessary replace the Count of Sampaio.