More so than other prominent generals at the time, Wei was known for using atypical strategies in both offense and defense, including extensive use of espionage and forgeries to undermine the morale of opposing forces.
During Northern Wei
Wei Xiaokuan was born in 509, during Western Wei's predecessor Northern Wei -- specifically, during the reign of . His clan was a prominent one in the Sanfu region, and both his grandfather Wei Zhishan and Wei Xu were commandery governors during Northern Wei. Wei Xiaokuan's given name was actually Wei Xiaoyu, but for reasons lost to history, he became known to others largely by his courtesy name of Xiaokuan.
In Wei Xiaokuan's youth, he was described to be studious and calm. When the general Xiao Baoyin rebelled in 527 and seized the Chang'an region, he was at the capital Luoyang, and he volunteered to serve in the army against Xiao. He served as an officer under Zhangxun Chengye the Duke of Fengyi and contributed to the army's success, and he was given a post as a teacher at the national university in Luoyang, and then an acting commandery governor. He later served under the prominent official Yang Kan , guarding the Tong Pass, when Yang, impressed by him, gave a daughter to him in marriage. Wei became a general during the reign of and was created the Baron of Shanbei. During the subsequent reign of , he served under the official Yuan Zigong , the governor of Jing Province as a commandery governor. It was at this time he became friends with fellow general Dugu Xin , who was also a commandery governor in Jing Province.
In the subsequent reign of , Wei was given the task of defending Jing Province, although he was not then governor. Subsequently, when Emperor Xiaowu, seeking to evade the influence of the paramount general Gao Huan, fled west to Chang'an, then controlled by Yuwen Tai, in 534, the empire became divided into Western Wei and Eastern Wei . It is unclear when or how, but Wei eventually joined the Western Wei regime in Chang'an, but it is not clear whether that happened before or after Emperor Xiaowu's death in 535 and replacement by his cousin Emperor Wen of Western Wei.
During Western Wei
In 538, during a major campaign between Western Wei and Eastern Wei, Wei Xiaokuan accompanied Emperor Wen, and he was made the governor of Hongnong Commandery . He subsequently entered Luoyang with Dugu Xin, and for some time tried to defend the city, but eventually they were forced to withdrew from the vicinity of Luoyang. As Wei was then stationed on the borders with Eastern Wei, he became concerned that the Eastern Wei general Niu Daoheng was capable at drawing the common people of the border region to join Eastern Wei's cause. Wei employed a tactic that he would reuse later -- first sending spies to steal samples of Niu's handwriting, and then employing forgers to forge letters purportedly from Niu to Wei offering to defect to Western Wei. He then intentionally allowed spies sent by Niu's superior Duan Chen to steal the forgeries, causing Duan to suspect Niu's loyalty and begin to refuse to follow Niu's suggestions. Once Wei was sure of the dissension within the Eastern Wei forces, he made a surprise attack and captured both Duan and Niu, taking the locale for Western Wei.
In 539, Emperor Wen promoted Wei's title from baron to marquess.
In 542, Wei was made the governor of Jin Province , and by the recommendation of the prominent general Wang Sizheng , was given by Yuwen Tai the responsibility of defending the important fort of Yubi , which Wang himself had defended earlier. He managed to pacify the province against raids by the ethnic Xiongnu tribesmen in the area.
In 546, Gao Huan launched a major attack on Western Wei, and as Yubi was an important fort on his path, he put it under siege. He built earthworks to surround the city, hoping to be able to breach Yubi's defenses on top of the walls, but Wei managed to build on top of the towers on top of the walls, always maintaining a higher vantage point than the earthworks and therefore stopping the Eastern Wei attack. Gao then tried digging tunnels below the walls, but Wei was able to anticipate this and dig tunnels himself to connect with Eastern Wei's tunnels, and then setting fires within the tunnels, burning the Eastern Wei soldiers to death. He further set fires to the Eastern Wei army's battering rams, and for every offensive strategy Gao was able to think of, Wei was able to counter it. Gao had his secretary Zu Ting write a letter to Wei, urging him to surrender, but Wei refused. Gao was unable to capture the fort after 60 days of siege, and he grew angry and ill and was forced to withdraw. For Wei's contributions, he was created the Duke of Jianzhong.
In 553, during the reign of Emperor Wen's son , Wei was made the governor of the capital region, Yong Province . In 554, Wei participated in the campaign commanded by Yu Jin against Liang Dynasty, which eventually captured its capital Jiangling and its emperor . After this campaign, Wei's title was changed to Duke of Rang, and as at the time, Yuwen Tai was choosing prominent generals to have their names changed to Xianbei names, Wei's name was changed to Yuwen, probably as a sign of respect and endearment on Yuwen Tai's part. In 556, when Yuwen Tai was carrying out a tour of the northern provinces, he returned Wei to the responsibility of defending Yubi.
During Emperors Xiaomin and Ming's reigns
Yuwen Tai died later in 556, leaving his son and heir under the guardianship of his nephew Yuwen Hu. Around the new year 557, Yuwen Hu forced Emperor Gong of Western Wei to yield the throne to Yuwen Jue, ending Western Wei and founding Northern Zhou, with Yuwen Jue taking the throne as Emperor Xiaomin, but with the alternative title of "Heavenly Prince" . Wei was made the deputy minister of the interior. After Yuwen Hu removed and killed Emperor Xiaomin later in 557 and replaced him with another son of Yuwen Tai, the Duke of Ningdu , Wei took on the additional responsibility as an imperial researcher. In 560, Yuwen Hu poisoned Emperor Ming to death, and Emperor Ming's brother the Duke of Lu became emperor .
During Emperor Wu's reign
In 561, in recognition of Wei's great victory at Yubi previously, Yubi and the surrounding area was made into Xun Province , and Wei was made its governor. During this tenure, Wei was said to be gracious to the people of the province while continuing to effectively employ a network of spies. For example, when his officer Xu Pen defected to Northern Qi, Wei sent spies after him, and was quickly able to have him killed.
Around this time, Xun Province continued to be plagued by raids by the ethnic Xiongnu who, while not submitting to either Northern Zhou or Northern Qi, were based within Northern Qi territory and cut off river traffic on the Fen River . In order to cut off the route of their raids, Wei sent his officer Yao Yue to build a fort near the Fen River. Yao initially was fearful that as his troops were building the fort that Northern Qi would launch an attack against him, but Wei warded off Northern Qi attacks by setting up bonfires in the surrounding hills, making Northern Qi forces believe that Yao was being reinforced by a large army, and therefore did not attack Yao, allowing Yao to complete the fort.
In 564, Wei helped negotiate an agreement where Northern Qi returned Yuwen Tai's sister and sister-in-law to Northern Zhou in exchange for peace. When, late in 564, Yuwen Hu nevertheless was preparing to launch an attack on Northern Qi (in order to placate the northern ally Tujue, Wei sent his secretary Xin Daoxian to try to dissuade Yuwen Hu, but Yuwen Hu nevertheless launched the attack, which was unsuccessful. In 570, the two states were stalemated while fighting for the control of the city of Yiyang . Wei, believing that Yiyang was not worth the effort and instead was apprehensive that Northern Qi would encroach on territory north of the Fen River, sent a proposal to Yuwen Hu to build forts north of the Fen River to guard the territory. Yuwen Hu, however, responded, "While Duke Wei has many descendants, they do not yet number a hundred. Who will be able to guard those forts?" Thereafter, the forts were not built.
Later in 570, Wei's title was promoted to Duke of Xun. That winter, as forewarned by Wei, the Northern Qi general Hulü Guang encroached on Northern Zhou territory north of the Fen River and built forts there, seizing substantial territory. Wei personally met Hulü on the border to try to dissuade him from the campaign, but Hulü did not relent. The armies stalemated after Yuwen Hu sent reinforcements commanded by Emperor Wu's brother Yuwen Xian the Duke of Qi, but territory was already lost.
By 572, however, Hulü was in conflict with the powerful officials Zu Ting and Mu Tipo, both of whom were trusted by the Northern Qi emperor Gao Wei. Wei, hearing this, wanted to create further suspicions in Gao Wei's mind against Hulü, and he decided to try to create a sense that Hulü would rebel. He wrote two songs in couplets, one of which read:
:''A hundred ''sheng'' will fly up to the heavens,''
:''A bright moon will shine over Chang'an.''
The other read:
:''The high mountain will collapse on its own,''
:''The daimyo oak will stand straight on its own.''
He sent spies to spread the songs near Northern Qi's capital , and the songs soon became popular. Zu, exploiting the situation himself, added two more lines:
:''The blind man will bear a great axe,''
:''The talkative woman will be unable to speak.''
Both Zu, who was blind, and Mu's mother Lu Lingxuan both discussed the songs with Gao Wei, and Gao Wei, his suspicions having been aroused, eventually agreed to have Hulü put to death, greatly weakening the Northern Qi military efforts.
After Hulü's death, Emperor Wu became particularly ambitious at conquering Northern Qi, and seeing this, Wei submitted three strategies for conquering Northern Qi to Emperor Wu. Also around this time, on account of his old age, Wei repeatedly made offers to resign and retire, but Emperor Wu repeatedly responded with edicts of kind words requesting him to stay.
In 576, when Emperor Wu launched a major attack on Northern Qi, he visited Yubi and praised Wei for his defense of the fort. Wei offered to be the forward commander for the attack, but Emperor Wu declined on reason that he needed Wei to defend Yubi still. However, he sent Wei to assist his brother Yuwen Zhao the Prince of Zhao in a secondary campaign near Yubi. After Emperor Wu conquered Northern Qi in 577, he returned to Yubi and took Wei back to the capital Chang'an with him, promoting Wei to the post of minister of agriculture. Subsequently, however, Emperor Wu made Wei the governor of Yan Province , in charge of the surrounding provinces.
During Emperors Xuan and Jing's reigns
Emperor Wu died in 578, and his son the Crown Prince succeeded him . In 579, Emperor Xuan passed the throne to his young son the Crown Prince , although he held onto power as retired emperor (with the atypical title of "Emperor Tianyuan" . Later that year, Emperor Xuan made Wei Xiaokuan in charge of Xu Province and the surrounding provinces, and Wei subsequently participated in the campaign against rival Chen Dynasty that allowed Northern Zhou to seize the region between the Yangtze River and Huai River from Chen. Wei's contribution was in capturing the important city of Shouyang, and when Emperor Xuan's cousin Yuwen Liang the Duke of Qi, angry and fearful that Emperor Xuan had recently raped his daughter-in-law , tried to ambush Wei to seize his troops to further act against Emperor Xuan, Wei defeated Yuwen Liang. For these achievements, one of Wei's sons was created the Duke of Hua.
In 580, Emperor Xuan died, and Emperor Xuan's father-in-law the Duke of Sui -- the son-in-law of Wei's great friend Dugu Xin -- became regent. Yang, suspicious that the general Yuchi Jiong , in charge of Xiang Province and the surrounding regions, tried to replace Yuchi with Wei. Weichi, however, was suspicious that Yang was intending to usurp the throne, decided to rise against Yang. When Wei approached Xiang Province, he realized this, and he pretended to be ill, and instead tried to flee to Luoyang -- on the way, leaving instruction to each post to give feasts to Yuchi's soldiers if they gave chase. Weichi indeed sent soldiers after Wei, but the soldiers were slowed by the feasts given to them, and were not able to track Wei down. Once Wei reached Luoyang, he carefully guarded the city, and although the ethnically Xianbei soldiers in the city considered rising in support of Weichi, they ultimately did not do so.
Yang then put Wei in charge of the army against Weichi. He first defeated Yuchi's general Xue Gongli , who was attacking Huai Province , and then crossed the Yellow River north. He defeated Yuchi's son Yuchi Dun near Weichi's headquarters at Yecheng
and then put Yecheng under siege. The city soon fell, and Yuchi Jiong committed suicide. Wei slaughtered the core troops that remained loyal to Yuchi to the end. Wei returned to Chang'an victoriously, and died a month later.