gpt4 book ai didi

powershell - Install-Module -Name newtonsoft.json - 在我关闭并重新打开 ISE 之前一直有效

转载 作者:行者123 更新时间:2023-12-03 00:56:53 29 4
gpt4 key购买 nike

在 PowerShell 5.1 中,我运行了这个:

Install-Module -Name newtonsoft.json

我能够在此声明中使用该库:
$jsonText = [Newtonsoft.Json.JsonConvert]::SerializeXmlNode($xmlDoc)

然后我关闭了 PowerShell,并运行了相同的脚本,但它失败了。
Unable to find type [Newtonsoft.Json.JsonConvert].

如果我执行“ Get-InstalledModule”,那么 newtonsoft.json 会显示在列表中 (1.0.2.201)。

现在,即使我再次运行安装命令,它仍然会出现上述错误。

也许我正在把自己挖得更深,但我试过这个:
Add-Type -Path "c:\Program Files\WindowsPowerShell\Modules\newtonsoft.json\1.0.2.201\libs\Newtonsoft.Json.dll"

现在它给出了错误:
Method invocation failed because [Newtonsoft.Json.JsonConvert] does not contain a method named 'SerializeXmlNode'.

是否将“Install-Module”永久添加?它创建了一个目录: c:\Program Files\WindowsPowerShell\Modules\newtonsoft.json

最佳答案

您应该使用 Install-Module一次然后在你的脚本中使用 Import-Module :

Import-Module newtonsoft.json

您将在 About-Modules 中找到更多信息.

关于powershell - Install-Module -Name newtonsoft.json - 在我关闭并重新打开 ISE 之前一直有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61873451/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com