[.NET] แก้ปัญหา Build แล้ว Error Your project file doesn’t list ‘win’ as a “RuntimeIdentifier”

Blog ตอนนี้ยังเป็น Blog ที่สรุปหลังปรับ Framework ขององค์กรครับ จาก Blog ก่อนหน้าที่ Error "The build is configured to run SonarQube analysis but the SonarQube analysis targets could not be located"

คราวนี้มาเจอ Error ใหม่ ที่มันกวนตีนกว่าเดิมครับ เพราะ มันเป็นบ้าง ไม่เป็นบ้าง และถ้า Build ผ่านตัว Visual Studio ไม่เจอนะ แต่ถ้า Build ผ่าน Command line พบเจ้า Error โผล่มาครับ

Your project file doesn't list 'win' as a "RuntimeIdentifier". You should add 'win' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore.

ปัญหานี้เกิดจากอะไร

  • เกิดจาก NuGet แหละครับ บางทีมัน Restore Package มาไม่ครบทำ ทำให้ตอน Build มัน Error ขึ้นมาครับ
  • และก็ถ้าเป็น Project ที่เป็น .NET Framework ยังแนะนำให้ใช้ msbuild.exe ในการสั่ง build แทน dotnet.exe ครับ

การแก้ไขหละ ทำอย่างไร ?

  • ทำให้ตัว Solution / Project ของเรา มันถูกสั่งให้ตรวจสอบ และ Restore Package / SDK ที่จำเป็นก่อนเหมือนกันตอนที่สั่ง Build ผ่าน Visual Studio ครับ โดยใช้คำสั่ง ดังนี้ ครับ
MSBuild -t:restore "<PATH TO SOLUTION / CS PROJECT" 
  • ตัวอย่างการใช้ครับ ของผมขออ้าง Path MSBuild.exe แบบเต็มๆเลยนะครับ ที่ถูกสั่งให้ Restore ไฟล์ WebAPI.sln ครับ
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe" -t:restore "D:\\APP\WebAPI.sln" 

Reference