问题描述
我正在尝试在未连接到 Internet 的 Win 7 计算机上通过 Powershell 命令行安装 pswindowsupdate.2.0.0.4.nupkg
.我正在运行 PS 5.1.14409.1005.我从 https://www.preview.powershellgallery.com/packages/获得了 nupkgPSWindowsUpdate/2.0.0.4
I'm trying to install pswindowsupdate.2.0.0.4.nupkg
from the Powershell command line on a Win 7 computer not connected to the internet. I'm running PS 5.1.14409.1005. I obtained the nupkg from https://www.preview.powershellgallery.com/packages/PSWindowsUpdate/2.0.0.4
PS
命令 Install-Module -Name pswindowsupdate.2.0.0.4.nupkg -Repository {path to pswindowsupdate.2.0.0.4.nupkg}
抛出错误消息:
The PS
command Install-Module -Name pswindowsupdate.2.0.0.4.nupkg -Repository {path to pswindowsupdate.2.0.0.4.nupkg}
throws an error message:
PowerShellGet 需要 NuGet 提供程序版本2.8.5.201"或更高版本才能与基于 NuGet 的存储库进行交互.NuGet 提供程序必须在C:Program FilesPackageManagementProviderAssemblies"或C:Users{my login}AppDataLocalPackageManagementProviderAssemblies"中可用.您还可以通过运行Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force"来安装 NuGet 提供程序.是否希望 PowerShell 现在安装和导入 NuGet 提供程序?
说是"当然无法安装 NuGet 提供程序,因为我没有连接到互联网.
Saying 'yes', of course, fails to install the NuGet provider because I'm not connected to the internet.
我获得了 nuget.exe
(v4.7.0),将其存储在C:Program FilesPackageManagementProviderAssemblies"中,并将C:Program FilesPackageManagementProviderAssemblies"添加到我的path
语句.但是,执行 Install-Module -Name pswindowsupdate.2.0.0.4.nupkg -Repository {path to pswindowsupdate.2.0.0.4.nupkg}
仍然失败.
I obtained nuget.exe
(v4.7.0), stored it in 'C:Program FilesPackageManagementProviderAssemblies' and added 'C:Program FilesPackageManagementProviderAssemblies' to my path
statement. However, executing Install-Module -Name pswindowsupdate.2.0.0.4.nupkg -Repository {path to pswindowsupdate.2.0.0.4.nupkg}
still fails.
究竟什么是NuGet 提供者
?它只是nuget.exe吗?如何获取并安装适用于 PowerShell 的 Nuget 提供程序(v2.8.5.201 或更高版本),以便我可以从 PowerShell 命令行安装此 nuget 包?
What exactly is a NuGet provider
? Is it just nuget.exe? How do I obtain and install the Nuget provider (v2.8.5.201 or greater) for PowerShell so I can install this nuget package from the PowerShell command line?
注意:Visual Studio 与我的问题没有任何关系
推荐答案
MSDocs 为您的场景说明了这一点:
MSDocs state this for your scenario:
为了第一次执行,PackageManagement 需要一个互联网连接以下载 Nuget 包提供程序.然而,如果您的计算机没有互联网连接并且您需要使用 Nuget 或 PowerShellGet 提供程序,您可以在另一台计算机并将它们复制到您的目标计算机.使用执行此操作的步骤如下:
运行
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force
以从具有 Internet 连接的计算机安装提供程序.
Run
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force
to install the provider from a computer with an internet connection.
安装后可以在$env:ProgramFilesPackageManagementReferenceAssemblies\<ProviderName>\<ProviderVersion>中找到安装的provider或者
$env:LOCALAPPDATAPackageManagementProviderAssemblies\<ProviderName>\<ProviderVersion>
.
将文件夹(在本例中为 Nuget 文件夹)放置在目标计算机上的相应位置.如果你的目标计算机是 Nano 服务器,您需要运行从 Nano Server Install-PackageProvider 下载正确的 Nuget二进制文件.
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.
重启 PowerShell 以自动加载包提供程序.或者,运行
Get-PackageProvider -ListAvailable
列出所有计算机上可用的软件包提供程序.然后使用Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201
到将提供程序导入当前的 Windows PowerShell 会话.
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 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!