In 1370, Zhu Yuanzhang ordered his general, Tang He, to occupy Xuande (), later changed to Xuanfu (), Hua Yunlong to occupy Yunzhou (), seated in the north of Chicheng. Xuanfu was one of the Nine Garrisons of the Ming dynasty. In order to defend China proper from invasions from the north, Ming emperors, especially Yongle Emperor (who sent the fleet of Zheng He journeying as far as East Africa) put great emphasis on the building of defensive forces in northern China, where most troops were deployed in Xuanfu, reaching 151 thousand during 1403 to 1424. Fighting Mongols, Yongle Emperor's campaigns against the Mongols mainly took place to the north of Zhangjiakou. In 1429, the construction of Zhangjiakoubu () was started. The castle was one defensive stronghold in the Great Walls.