返回上一頁

Private Nuget Server 指令操作說明

以下為 command 紀錄,下 command 的位置為 csproj 檔所在位置

nuget.exe 可於 https://www.nuget.org/downloads 取得,下載 Windows x86 Commandline 的 recommended latest 版本即可。

要在任何位置都要能執行 nuget.exe ,需要將 nuget.exe 執行檔的所在位置加入至環境變數的 Path 內容中

## 建立 nuget 封裝描述檔

僅於封裝描述不存在時執行

指令:

nuget spec

輸出結果:

已成功建立 'MyLibrary.nuspec'。

將專案打包為 nuget 封裝

每次打包封裝前,需要確認專案內的版本號資訊已經更新為下一個版本號,並重新建置過,以免打包出同版號的原件

指令:

nuget pack MyLibrary.csproj -Properties Configuration=Release

輸出結果:

正在嘗試從 'MyLibrary.csproj' 建置封裝。
MSBuild auto-detection: using msbuild version '15.5.180.51428' from 'C:\Program File
s (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin'.
正在封裝 ‘****MyLibrary\src\bin\Release' 中的檔案。
正在使用中繼資料的 'MyLibrary.nuspec'。
找到 packages.config。使用列出的封裝做為相依性。

Successfully created package ‘****MyLibrary\src\MyLibrary.3.0.0.nupkg'.

將 nuget 封裝推送至 nuget server

指令:

nuget push MyLibrary.3.0.0.nupkg {apiKey} -Source https://nuget.example.com/nuget

輸出結果:

Pushing MyLibrary.3.0.0.nupkg to 'https://nuget.example.com/nuget'...
  PUT https://nuget.example.com/nuget/
請提供以下項目的認證: https://nuget.example.com/nuget
使用者名稱: john_doe
密碼: ********
  Created https://nuget.example.com/nuget/ 17168ms
Your package was pushed.

移除 nuget server 上指定版本的封裝檔

用於發錯檔案需抽回時,也可直接連上 server 刪除,須注意已經發上 server 的套件如果已經被其他人 pull 下來,重發同版號的原件後其他人 local 的 cache 仍需請對方手動清除,建議刪除後下次上版也應該跳號。

指令:

nuget delete MyLibrary 3.0.0 {apiKey} -Source https://nuget.example.com/nuget

輸出結果:

MyLibrary 3.0.0 will be deleted from the 'https://nuget.example.com/nuget'. Would you like to continue? (是/否) 是
警告: Deleting MyLibrary 3.0.0 from the 'https://nuget.example.com/nuget'.
  DELETE https://nuget.example.com/nuget/MyLibrary/3.0.0
請提供以下項目的認證: https://nuget.example.com/nuget
使用者名稱: gary
密碼: ********
  NoContent https://nuget.example.com/nuget/MyLibrary/3.0.0 10349ms

MyLibrary 3.0.0 was deleted successfully.

將 private nuget server 加入 nuget source 清單內

每個開發環境只需執行一次

指令:

nuget.exe sources add -name NUGET  -Source https://nuget.example.com/nuget

輸出結果:

具有名稱的封裝來源: NUGET 已成功新增。