With the creation of the Cisalpine Republic under Napoleonic occupation, Giovanni was named one of the directors of the new government. But a dispute with general Brune led to his dismissal. With the return of Hapsburg government, he was imprisoned at the Fort of Cattaro. After the Battle of Marengo, and the defeat of the Austrians, he was recalled to government. He held a variety of positions, including president of the Senate in the years 1809, 1811, and 1812. He supported Napoleon's goals to claim the title of king of Italy, and as a reward was granted a title of count, and awards of the Iron Crown and Legion of Honor. He lobbied unsuccessfully to have Eugène de Beauharnais named as king of the North Italian republic. With Napoleon's fall, his main income was teaching mathematics.