[.NET] กำหนด Version ตอน Build หรือ Pack

  • ช่วงนี้มีทำ Script เกี่ยวกับการ Build เลย ขอแปะตัว snippet command ไว้ครับ โดยการจะ Set Version เราสามารถกำหนดได้จาก 2 คำสั่งครับ
    • dotnet build - สำหรับ Build DLL/exe
    • dotnet pack - สำหรับ Build + สร้าง Nuget Package ขึ้นมาด้วย
  • เรากำหนด Version อะไรได้บ้าง
Version Type
ที่เป็นไปได้
dotnet builddotnet packRemark
-p:AssemblyVersionFile Explorer = File Version
//4 หลัก
-p:VersionFile Explorer = Product Version
//4 หลัก แต่ถ้าใช้ dotnet pack จะได้ 3 หลัก
-p:PackageVersionNuget Package Version
อันนี้ใส่ String ต่อท้ายได้
เช่น
-p:PackageVersion=
2.0.0-pre-alpha
  • ตัวอย่าง Pattern กรณีที่ใช้ dotnet build
dotnet build ds.Common.sln -c Release -p:AssemblyVersion=5.4.3.2 p:Version=5.4.3
  • ตัวอย่าง Pattern กรณีที่ใช้ dotnet pack
dotnet pack ds.Common.sln -c Release --include-source --include-symbols -o nuget -p:PackageVersion=5.4.3.2 -p:AssemblyVersion=5.4.3.2 -p:Version=5.4.3
  • แถมตัว Script เต็มๆ ครับ กรณี Restore + Pack + Publish ครับ
dotnet restore ds.Common.sln --source "https://api.nuget.org/v3/index.json;http://dev.ds.local:8081/repository/nuget-hosted/;http://dev-dr.ds.local:8081/repository/nuget-hosted/" --ignore-failed-sources'
dotnet pack ds.Common.sln -c Release --include-source --include-symbols -o nuget -p:PackageVersion=2.0.0-pre-alpha -p:AssemblyVersion=2.0.0 -p:Version=2.0.0-pre-alpha
cd nuget
dotnet nuget push "*.nupkg" --api-key e2f11sdc86-36sdsb2-3183-9416-e2f11sdc86--source http://dev.ds.local:8081/repository/nuget-hosted/

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.