dotnet專案CICD研究整理2

.NET CORE專案相關Library套件NuGet管理與Nexus相關實作

ZONGRU Li
7 min readAug 22, 2023

找到網路上有人寫好的nugetimport.sh

這個看起來是可以直接在有裝git bash的windows下執行:

參考以下這個單一上傳Nexus範例(LINK):

加入NuGet API Realm:

就可以在帳號頁面取得NuGet API Key:

還有nuget.exe

放到:

#在C:\Users\User\.nuget\packages也就是套件旁邊放好nuget.exe與sh後執行以下:
./nugetimport.sh -r {nuget-hosted的URL} -k {Nexus上的NuGet API Key}

後面其他package上傳成功的log就不截圖了

然後Nexus上面看到:

我嘗試先移除上面negut-hosted的內容:

嘗試讓本機指令驅動去跟Nexus要套件

理論上一般公司內離線環境是去跟nuget.org-proxy要套件

然後Nexus上的nuget.org-proxy會去跟NuGet公庫索取套件

目前是空的

然後清空本機:

如果只是VS上面打包只要設定:

LINK

然後確認後是要先執行dotnet restore指令來從Nexus下載套件

之後才做build或publish

但是會卡到Nexus權限帳密不知道怎麼帶

#後來找到微軟文件(LINK):
dotnet nuget add source http://{Nexus IP}:8081/repository/nuget.org-proxy/ --name {給定這個Repo名稱例如nuget.org-proxy} --username <user> --password <password> --store-password-in-clear-text
#印出目前設定的Source:
dotnet nuget list source
#移除套件源:
dotnet nuget remove source {add時候給的名稱}

然後我測試過程不小心沒給名子就建立了Source

找到這個設定檔案實際會出現在(參考LINK):

手動移除後再list看到:

後來找到新增Nexus上面那個proxy的Repo是要(LINK):

#加入Nexus的proxy的Repo,要指定到index.json檔案:
dotnet nuget add source http://{Nexus IP}:8081/repository/nuget-proxy/index.json --name nuget-proxy

#我實際還會給帳秘等,組成這樣:
dotnet nuget add source http://{Nexus IP}:8081/repository/nuget-proxy/index.json --name nuget-proxy --username <user> --password <password> --store-password-in-clear-text
要指到裡面預設有的這個json檔案

先確保目前本機是空的:

#移除剛剛的nuget-proxy:
dotnet nuget remove source nuget-proxy

重新加入另一個Repo →nuget-group:

#組成這樣:
dotnet nuget add source http://{Nexus IP}:8081/repository/nuget-group/index.json --name nuget-group --username <user> --password <password> --store-password-in-clear-text
#接著嘗試dotnet restore指令指定從Nexus拉套件:
dotnet restore --source http://{Nexus IP}:8081/repository/nuget-group/index.json

看起來成功:

發現遠端有套件:

地端使用者目錄有套件:

但是專案的bin/Debug/{Framework版號}/底下是空的:

但是另一邊的obj目錄有異動,只是沒看到Library:

時間是剛剛的沒錯

所以看起來只是把套件準備好到本機,但還沒到專案內

#接著執行build(預設會build到Debug目錄去,所以也寫清楚指定):
dotnet build --configuration Debug

看到bin/Debug/{Framework版號}/底下就建出來了

#理論上就可以publish到Release去:
dotnet publish --configuration Release

執行前我先移除:

執行後看到:

這層底下的東西就是準備佈署到IIS的佈署目錄(有看到web.config)

相關參考(LINK1)

相關參考(LINK2)

相關參考(LINK3)

相關參考(LINK4)

--

--

ZONGRU Li
ZONGRU Li

Written by ZONGRU Li

2022/11/17 開源部分個人筆記給LINE "Java程式語言討論區"社群,希望能對社群的技術學習做一點點貢獻.(掩面....記得退訂閱!

No responses yet