Powershell:如何在未连接的机器上安装 PowerShell 的 Nuget 提供程序,以便我可以从 PS 命令行安装 nuget 包? [英] Powershell: How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line?

查看:537
本文介绍了Powershell:如何在未连接的机器上安装 PowerShell 的 Nuget 提供程序,以便我可以从 PS 命令行安装 nuget 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在未连接到 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 Files\PackageManagement\ProviderAssemblies"或C:\Users{my login}\AppData\Local\PackageManagement\ProviderAssemblies"中可用.您还可以通过运行Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force"来安装 NuGet 提供程序.是否希望 PowerShell 立即安装和导入 NuGet 提供程序?

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?

当然,说是"无法安装 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 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} 仍然失败.

I obtained nuget.exe (v4.7.0), stored it in 'C:\Program Files\PackageManagement\ProviderAssemblies' and added 'C:\Program Files\PackageManagement\ProviderAssemblies' 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 提供程序,您可以在另一台计算机并将它们复制到您的目标计算机.使用执行以下步骤:

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. 运行 Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force 以从具有互联网连接的计算机安装提供程序.

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

安装后,可以在$env:ProgramFiles\PackageManagement\ReferenceAssemblies\\\<ProviderName\>\\\<ProviderVersion\>中找到安装的provider或者$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies\\\<ProviderName\>\\\<ProviderVersion\>.

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

将文件夹(在本例中为 Nuget 文件夹)放在目标计算机上的相应位置.如果你的目标计算机是 Nano 服务器,您需要运行从 Nano Server 安装 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 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆