In the early 18th century the Swedes invaded Norway again, and this time the Norwegian army held its own, setting the stage for nearly a century of peace – the longest yet in modern Norwegian history – during which time a distinct Norwegian identity began to evolve. German ceased to be the official language of command in the army in 1772, in favour of "Dano-Norwegian". With the outbreak of the Napoleonic Wars (1803–1815), the kingdoms of Denmark–Norway and Sweden tried to remain neutral; but Denmark's King Frederik IV's decision to align with French Emperor Napoleon I meant that hostilities reached north into Scandinavia and Norway. By 1807, Denmark-Norway was formally at war with Great Britain.