[NUGET] dotnet restore error 401

เนื่องจาก Nexus ที่ บ ใช้งานอยู่ มีปรับ Policy ใหม่ พวก Private Repository ต้องมีการ Authentication ก่อนเข้าใช้งานครับ สำหรับเครื่อง DEV / Build เลยต้องมีการแก้ไขเพิ่ม ดังนี้

  • เพิ่ม NuGet Repository Username / Password โดยใช้คำสั่ง dotnet nuget
dotnet nuget add source <nuget server> --name <name> --username <user> --password <password> 
  • ตัวอย่าง
dotnet nuget add source "http://dev.local:10081/repository/nuget-hosted/" --name "dev.local" --username chatri --password yourPassword 
  • ตรวจสอบไฟล์ที่แก้ไข จาก Path %AppData%\NuGet\NuGet.config ครับ อย่างผมเพิ่มของ DC/DR เข้าไปจะได้มา 2 source ครับ
  • หรือจะดูจากคำสั่ง
dotnet nuget list source
  • Note สำหรับ non windows ต้องเติม option --store-password-in-clear-text ต่อท้าย ด้วยไม่งั้น add source nuget ไม่ได้ครับ

ใช้ API Key ได้ไหม ?

  • ไม่ได้ API Key ออกแบบมาสำหรับตอน Publish Package อันนี้ผมก็งงกับทีมพัฒนาเหมือนกัน อ้างอิงจาก Does the API key replace a username and a password in Nuget? - Stack Overflow (ตอนแรกลองแบบ API แล้วมันไม่ได้ครับ 555)

ถ้าไม่ใช่แล้ว ลบออกได้ไหม

  • ได้ครับ โดยใช้คำสั่ง
dotnet nuget remove source <name>
  • ตัวอย่าง
dotnet nuget remove source "dev.local"

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.