啟動 Windows PowerShell 5.1 的 NuGet 元件
在新的 Windows 部署上,Windows PowerShell 5.1 不包含必要的 NuGet 元件,以與 PowerShell 資源庫互動。 只要您可以連線到PowerShell資源庫,PowerShellGet即包含更新這些元件的邏輯。 如果計算機未連線到因特網,您必須將所需的檔案從受信任的來源複製到已中斷連線的計算機。
必要的 NuGet 元件會包含在 PowerShellGet v2+ 和 PackageManagement v1.1+ 中。 這些模組的較新版本可從PowerShell資源庫取得,並包含在PowerShell 6和更新版本中。 這些指示適用於 Windows PowerShell 5.1。
重要
啟動載入 NuGet 元件之後,您必須安裝最新版的 PowerShellGet 和 PackageManagement 模組才能受到支援。
在連線到因特網的計算機上啟動程式
下列程式假設計算機已連線到因特網,而且可以從公用位置下載檔案。
錯誤:需要 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.
未連線到因特網的計算機上啟動程式
下列程式假設計算機未連線到因特網。 若要安裝必要的元件,請遵循連線到因特網的機器上的啟動程式程式,然後透過離線信任的程式,手動將提供者複製到隔離節點。
將 NuGet 提供者檔案複製到離線電腦。
將
C:\Program Files\PackageManagement\ProviderAssemblies\NuGet
資料夾從連線的電腦複製到離線電腦上的相同位置。將 PowerShellGet 和 PackageManagement 模組複製到離機電腦。
將下列模組資料夾從連線的計算機複製到離線電腦上的相同位置。
C:\Program Files\WindowsPowerShell\Modules\PowerShellGet
C:\Program Files\WindowsPowerShell\Modules\PackageManagement