简体   繁体   English

如何在 Powershell 二进制模块 (.Net Standard & Nuget) 中处理公共和私有依赖项和打包

[英]How to handle public and private dependencies and packaging in Powershell binary module (.Net Standard & Nuget)

I have a sample project https://github.com/hagatorn/LunarSolarDate which is pre-release so please excuse the lack of finish.我有一个示例项目https://github.com/hagatorn/LunarSolarDate是预发布的,所以请原谅没有完成。

If I build the project I can import the module in the bin directory:如果我构建项目,我可以在 bin 目录中导入模块:

Import-Module .\SolarLunarName.PoSH.dll

However, when run the only command I am presented with an error.但是,当运行唯一的命令时,我遇到了错误。

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 

This was relatively easily resolved to pop the missing dll in the bin directory.在 bin 目录中弹出丢失的 dll 相对容易解决。 A less useful message then appeared but adding Newtonsoft.Json.dll and Newtonsoft.Json.pdb to the bin directory moved me onto a problem I will deal with in a separate question.然后出现了一条不太有用的消息,但是将 Newtonsoft.Json.dll 和 Newtonsoft.Json.pdb 添加到 bin 目录使我遇到了一个问题,我将在一个单独的问题中处理。

Manually copying dependencies around worried me a bit so I began to experiment trying to build and deploy with nuget and hope dependencies may be dealt with completely in this model.手动复制依赖关系让我有点担心,所以我开始尝试尝试使用 nuget 构建和部署,并希望可以在这个模型中完全处理依赖关系。

Having published the module and its private dependency as a published nuget package I can form the dependencies with the following command.将模块及其私有依赖项发布为已发布的 nuget 包后,我可以使用以下命令形成依赖项。

nuget.exe install SolarLunarName.PoSH 

However, in their initial state the dependencies are logically separated in a directory structure that renders them inaccessible to the binary module.但是,在它们的初始状态下,依赖项在一个目录结构中逻辑分离,这使得二进制模块无法访问它们。

Is there a better way of doing this as an integrated part of the build or package installation?作为构建或包安装的集成部分,有没有更好的方法来做到这一点? Can powershell do some package management and use the .deps.json to install the public dependencies? powershell 可以做一些包管理并使用 .deps.json 来安装公共依赖项吗?

I have seen another thread discussing forcing msbuild to include extra binaries in the bin directory output by making dummy calls to nested dependencies.我看到另一个线程讨论通过对嵌套依赖项进行虚拟调用来强制 msbuild 在 bin 目录输出中包含额外的二进制文件。 Despite the convenience of this solution it seemed a little wrong-headed and contrary to the logic of package management.尽管这个解决方案很方便,但它似乎有点错误并且与包管理的逻辑相反。 Dependent DLL is not getting copied to the build output folder in Visual Studio 依赖 DLL 没有被复制到 Visual Studio 中的构建输出文件夹

Also there is the following thread which I which I admit could be the same issue if package management is indeed working correctly and I have misunderstood the problem.还有以下线程,我承认如果包管理确实正常工作并且我误解了问题,我承认这可能是相同的问题。 PowerShell Binary Module assembly dependency error . PowerShell 二进制模块程序集依赖错误

Finally there was another lead regarding tagging your package as "PSModule" I believe I've done this in the visual studio project properties package page.最后还有一个关于将你的包标记为“PSModule”的线索,我相信我已经在 Visual Studio 项目属性包页面中做到了这一点。 But perhaps this isn't how to achieve that?但也许这不是实现这一目标的方法?

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.这个问题是由于缺乏具体的目标框架和依赖项不是用 .Net Standard 编写的,并且在最终编译到目标框架时会出现各种不同的包。

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.较新版本的 Rest Sharp 可能已经发布,它没有这个问题,但是一些 SQLite 驱动程序和 ORM 仍然有这个限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM