如何在 Powershell 二進制模塊(.Net Standard 和 Nuget)中處理公共和私有依賴項和打包 (How to handle public and private dependencies and packaging in Powershell binary module (.Net Standard & Nuget))


問題描述

如何在 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.

(by Craig.CCraig.C)

參考文件

  1. How to handle public and private dependencies and packaging in Powershell binary module (.Net Standard & Nuget) (CC BY‑SA 2.5/3.0/4.0)

#powershell #visual-studio #.net #nuget-package #.net-standard-2.0






相關問題

玩弄 C# 加密 (Playing around with C# encryption)

查找具有特定 startname 的特定服務 (Finding specific services with specific startname)

試圖從事件日誌中獲取數據到電子郵件中的 html (Trying to get data from event logs into html in email)

如何通過powershell獲取請求的authtoken (How to obtain authtoken for request via powershell)

如何在錯誤時繼續使用 &$var 調用可執行文件 (How to continue on error a call to an executable using &$var)

在同一範圍內從 c# 調用多個 powershell 命令 (Invoke multiple powershell commands from c# on the same scope)

如何在 Powershell 二進制模塊(.Net Standard 和 Nuget)中處理公共和私有依賴項和打包 (How to handle public and private dependencies and packaging in Powershell binary module (.Net Standard & Nuget))

如何使用參數(描述空白)獲取廣告中的所有 OU - 沒有描述? (How to get all OU in Ad with parameter (description blank ) - without description?)

遠程服務器返回錯誤:(400) 錯誤請求。在 C:\Program Files\WindowsPowerShell\Modules\CosmosDB\3.1.0.293\CosmosDB.psm1 (The remote server returned an error: (400) Bad Request. At C:\Program Files\WindowsPowerShell\Modules\CosmosDB\3.1.0.293\CosmosDB.psm1)

Powershell 檢查文件類型 (Powershell check file type)

服務器待重啟 (Server Pending Reboot)

PowerShell 的 Invoke-WebRequest 在 Docker 容器中不起作用 (PowerShell's Invoke-WebRequest not working within a Docker Container)







留言討論