gpt4 book ai didi

Powershell:如何在未连接的机器上安装 PowerShell 的 Nuget 提供程序,以便我可以从 PS 命令行安装 nuget 包?

转载 作者:行者123 更新时间:2023-12-04 01:31:40 25 4
gpt4 key购买 nike

我正在尝试安装 pswindowsupdate.2.0.0.4.nupkg从未连接到 Internet 的 Win 7 计算机上的 Powershell 命令行。我正在运行 PS 5.1.14409.1005。我从 https://www.preview.powershellgallery.com/packages/PSWindowsUpdate/2.0.0.4 获得了 nupkg
PS命令 Install-Module -Name pswindowsupdate.2.0.0.4.nupkg -Repository {path to pswindowsupdate.2.0.0.4.nupkg}抛出错误消息:

PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or 'C:\Users{my login}\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShell to install and import the NuGet provider now?



当然,说"is"无法安装 NuGet 提供程序,因为我没有连接到互联网。

我获得了 nuget.exe (v4.7.0),将其存储在“C:\Program Files\PackageManagement\ProviderAssemblies”中,并将“C:\Program Files\PackageManagement\ProviderAssemblies”添加到我的 path陈述。但是,执行 Install-Module -Name pswindowsupdate.2.0.0.4.nupkg -Repository {path to pswindowsupdate.2.0.0.4.nupkg}仍然失败。

究竟什么是 NuGet provider ?它只是nuget.exe吗?如何获取和安装 PowerShell 的 Nuget 提供程序(v2.8.5.201 或更高版本),以便我可以从 PowerShell 命令行安装此 nuget 包?

注意:Visual Studio 与我的问题没有任何关系

最佳答案

MSDocs 针对您的情况说明了这一点:

In order to execute the first time, PackageManagement requires an internet connection to download the Nuget package provider. However, if your computer does not have an internet connection and you need to use the Nuget or PowerShellGet provider, you can download them on another computer and copy them to your target computer. Use the following steps to do this:

  1. Run Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force to install the provider from a computer with an internet connection.

  2. After the install, you can find the provider installed in $env:ProgramFiles\PackageManagement\ReferenceAssemblies\\\<ProviderName\>\\\<ProviderVersion\> or $env:LOCALAPPDATA\PackageManagement\ProviderAssemblies\\\<ProviderName\>\\\<ProviderVersion\>.

  3. Place the folder, which in this case is the Nuget folder, in the corresponding location on your target computer. If your target computer is a Nano server, you need to run Install-PackageProvider from Nano Server to download the correct Nuget binaries.

  4. Restart PowerShell to auto-load the package provider. Alternatively, run Get-PackageProvider -ListAvailable to list all the package providers available on the computer. Then use Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 to import the provider to the current Windows PowerShell session.

关于Powershell:如何在未连接的机器上安装 PowerShell 的 Nuget 提供程序,以便我可以从 PS 命令行安装 nuget 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51406685/

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