問題描述
如何在 Powershell 二進制模塊(.Net Standard 和 Nuget)中處理公共和私有依賴項和打包 (How to handle public and private dependencies and packaging in Powershell binary module (.Net Standard & Nuget))
我有一個示例項目 https://github.com/hagatorn/LunarSolarDate 這是 pre ‑release 所以請原諒沒有完成。
如果我構建項目,我可以在 bin 目錄中導入模塊:
Import‑Module .\SolarLunarName.PoSH.dll
但是,當運行我唯一的命令時出現錯誤。
Get‑Date | Get‑SolarLunarName
Get‑SolarLunarName : Could not load file or assembly 'RestSharp, Version=106.6.2.0, Culture=neutral,
PublicKeyToken=598062e77f915f75' or one of its dependencies. The system cannot find the file specified.
At line:1 char:12
+ get‑date | Get‑SolarLunarName
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get‑SolarLunarName], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,SolarLunarName.PoSH.GetSolarLunarName
在 bin 目錄中彈出丟失的 dll 相對容易解決。然後出現了一條不太有用的消息,但是將 Newtonsoft.Json.dll 和 Newtonsoft.Json.pdb 添加到 bin 目錄使我遇到了一個問題,我將在單獨的問題中處理。
手動複製周圍的依賴關係讓我有點擔心,所以我開始嘗試嘗試使用 nuget 構建和部署,並希望可以在此模型中完全處理依賴關係。
已將模塊及其私有依賴項發佈為已發布nuget 包我可以使用以下命令形成依賴關係。
nuget.exe install SolarLunarName.PoSH
但是,在初始狀態下,依賴關係在邏輯上分離在一個目錄結構中,使二進制模塊無法訪問它們。
作為構建或軟件包安裝的集成部分,有沒有更好的方法?powershell 可以做一些包管理並使用 .deps.json 安裝公共依賴嗎?
我看到另一個線程討論通過對嵌套依賴項進行虛擬調用來強制 msbuild 在 bin 目錄輸出中包含額外的二進製文件。儘管這個解決方案很方便,但它似乎有點錯誤,並且與包管理的邏輯相反。依賴 DLL 不是被複製到 Visual Studio 中的構建輸出文件夾
如果包管理確實正常工作並且我誤解了問題,我承認以下線程可能是相同的問題. PowerShell 二進制模塊程序集依賴錯誤。
最後還有另一個關於將你的包標記為“PSModule”的線索我相信我已經在 Visual Studio 項目屬性包頁面中完成了這個。但也許這不是實現的方法?
參考解法
方法 1:
This problem was caused by a lack of a concrete target framework and a dependency which was not written in .Net Standard and had various different packages it would present when finally compiled to a target framework.
A newer version of Rest Sharp may have been released which does not have this problem however some SQLite drivers and ORMs still have this limitation.