启动适用于 Windows PowerShell 5.1 的 NuGet 组件
在 Windows 的新部署中,Windows PowerShell 5.1 不包括与 PowerShell 库交互所需的 NuGet 组件。 只要可以连接到 PowerShell 库,PowerShellGet 就包括更新这些组件的逻辑。 如果计算机未连接到 Internet,则必须将所需文件从受信任的源复制到断开连接的计算机。
所需的 NuGet 组件包含在 PowerShellGet v2+ 和 PackageManagement v1.1+ 中。 这些模块的较新版本可从 PowerShell 库获取,并包含在 PowerShell 6 及更高版本中。 这些说明适用于 Windows PowerShell 5.1。
重要
启动 NuGet 组件后,必须安装最新版本的 PowerShellGet 和 PackageManagement 模块才能得到支持。
在连接 Internet 的计算机上启动
以下过程假定计算机已连接到 Internet,并且可以从公共位置下载文件。
错误:需要 NuGet 提供程序才能继续
当计算机上的 NuGet 提供程序不可用时,会收到此错误。
Find-Module -Repository PSGallery -Verbose -Name Contoso
使用 Y
回答安装 NuGet 提供程序的提示。
NuGet provider is required to continue
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\PackageMan
agement\ProviderAssemblies' or 'C:\Users\user1\AppData\Local\PackageManagement\ProviderAs
semblies'. You can also install the NuGet provider by running 'Install-PackageProvider -N
ame NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and imp
ort the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
VERBOSE: Installing NuGet provider.
Version Name Type Repository Description
------- ---- ---- ---------- -----------
2.5 Contoso Module PSGallery Contoso module
错误:需要 NuGet.exe 才能继续
当 NuGet 提供程序可用,但 nuget.exe
二进制文件不可用时,会收到此错误。
Publish-Module -Name Contoso -Repository PSGallery -Verbose
使用 Y
回答安装 nuget.exe
的提示。
NuGet.exe is required to continue
PowerShellGet requires NuGet.exe to publish an item to the NuGet-based repositories. NuGe
t.exe must be available under one of the paths specified in PATH environment variable val
ue. Do you want PowerShellGet to install NuGet.exe now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
VERBOSE: Installing NuGet.exe.
VERBOSE: Successfully published module 'Contoso' to the module publish location 'https://
www.powershellgallery.com/api/v2/'.
Please allow few minutes for 'Contoso' to show up in the search results.
错误:需要 NuGet.exe 和 NuGet 提供程序才能继续
如果未安装 NuGet 提供程序和 nuget.exe
,则会收到此错误。
Publish-Module -Name Contoso -Repository PSGallery -Verbose
使用 Y
回答提示以安装 NuGet 提供程序和 nuget.exe
。
NuGet.exe and NuGet provider are required to continue
PowerShellGet requires NuGet.exe and NuGet provider version '2.8.5.201' or newer to inter
act with the NuGet-based repositories. Do you want PowerShellGet to install both NuGet.ex
e and NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
VERBOSE: Installing NuGet provider.
VERBOSE: Installing NuGet.exe.
VERBOSE: Successfully published module 'Contoso' to the module publish location 'https://
www.powershellgallery.com/api/v2/'.
Please allow few minutes for 'Contoso' to show up in the search results.
在未连接到 Internet 的计算机上启动
以下进程假定计算机未连接到 Internet。 若要安装必要的组件,请按照连接到 Internet 的计算机上的启动过程操作,然后通过脱机受信任进程手动将提供程序复制到隔离节点。
将 NuGet 提供程序文件复制到脱机计算机。
将
C:\Program Files\PackageManagement\ProviderAssemblies\NuGet
文件夹从连接的计算机复制到脱机计算机上的同一位置。将 PowerShellGet 和 PackageManagement 模块复制到脱机计算机。
将以下模块文件夹从连接的计算机复制到脱机计算机上的同一位置。
C:\Program Files\WindowsPowerShell\Modules\PowerShellGet
C:\Program Files\WindowsPowerShell\Modules\PackageManagement