Save-Package
將套件儲存到本機電腦,而不安裝它們。
Syntax
Save-Package
[-Name] <String[]>
[-RequiredVersion <String>]
[-MinimumVersion <String>]
[-MaximumVersion <String>]
[-Source <String[]>]
[-Path <String>]
[-LiteralPath <String>]
[-Credential <PSCredential>]
[-Proxy <Uri>]
[-ProxyCredential <PSCredential>]
[-AllVersions]
[-Force]
[-ForceBootstrap]
[-WhatIf]
[-Confirm]
[-ProviderName <String[]>]
[<CommonParameters>]
Save-Package
[-Path <String>]
[-LiteralPath <String>]
-InputObject <SoftwareIdentity>
[-Credential <PSCredential>]
[-Proxy <Uri>]
[-ProxyCredential <PSCredential>]
[-AllVersions]
[-Force]
[-ForceBootstrap]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Save-Package
[-Path <String>]
[-LiteralPath <String>]
[-Credential <PSCredential>]
[-Proxy <Uri>]
[-ProxyCredential <PSCredential>]
[-AllVersions]
[-Force]
[-ForceBootstrap]
[-WhatIf]
[-Confirm]
[-ConfigFile <String>]
[-SkipValidate]
[-Headers <String[]>]
[-FilterOnTag <String[]>]
[-Contains <String>]
[-AllowPrereleaseVersions]
[<CommonParameters>]
Save-Package
[-Path <String>]
[-LiteralPath <String>]
[-Credential <PSCredential>]
[-Proxy <Uri>]
[-ProxyCredential <PSCredential>]
[-AllVersions]
[-Force]
[-ForceBootstrap]
[-WhatIf]
[-Confirm]
[-ConfigFile <String>]
[-SkipValidate]
[-Headers <String[]>]
[-FilterOnTag <String[]>]
[-Contains <String>]
[-AllowPrereleaseVersions]
[<CommonParameters>]
Save-Package
[-Path <String>]
[-LiteralPath <String>]
[-Credential <PSCredential>]
[-Proxy <Uri>]
[-ProxyCredential <PSCredential>]
[-AllVersions]
[-Force]
[-ForceBootstrap]
[-WhatIf]
[-Confirm]
[-AllowPrereleaseVersions]
[-PackageManagementProvider <String>]
[-PublishLocation <String>]
[-ScriptSourceLocation <String>]
[-ScriptPublishLocation <String>]
[-Type <String>]
[-Filter <String>]
[-Tag <String[]>]
[-Includes <String[]>]
[-DscResource <String[]>]
[-RoleCapability <String[]>]
[-Command <String[]>]
[-AcceptLicense]
[<CommonParameters>]
Save-Package
[-Path <String>]
[-LiteralPath <String>]
[-Credential <PSCredential>]
[-Proxy <Uri>]
[-ProxyCredential <PSCredential>]
[-AllVersions]
[-Force]
[-ForceBootstrap]
[-WhatIf]
[-Confirm]
[-AllowPrereleaseVersions]
[-PackageManagementProvider <String>]
[-PublishLocation <String>]
[-ScriptSourceLocation <String>]
[-ScriptPublishLocation <String>]
[-Type <String>]
[-Filter <String>]
[-Tag <String[]>]
[-Includes <String[]>]
[-DscResource <String[]>]
[-RoleCapability <String[]>]
[-Command <String[]>]
[-AcceptLicense]
[<CommonParameters>]
Description
Cmdlet 會將 Save-Package
套件儲存到本機電腦,但不會安裝套件。
除非您指定 RequiredVerion,否則此 Cmdlet 會儲存套件的最新版本。 Path和LiteralPath參數互斥,無法新增至相同的命令。
範例
範例 1:將套件儲存至本機電腦
本範例會將最新版本的套件儲存到本機電腦上的目錄。 套件的相依性會隨套件一起下載。
PS> Save-Package -Name NuGet.Core -ProviderName NuGet -Path C:\LocalPkg
Name Version Source Summary
---- ------- ------ -------
Microsoft.Web.Xdt 3.0.0 Nuget Microsoft Xml Document Transformation (XDT) enables...
NuGet.Core 2.14.0 Nuget NuGet.Core is the core framework assembly for NuGet...
Save-Package
會使用 Name 參數來指定封裝。 套件會從 ProviderName 參數指定的存放庫下載。 Path參數會決定儲存封裝的位置。
範例 2:儲存特定套件版本
此範例會指定套件版本,並將它儲存到本機電腦上的目錄。
PS> Save-Package -Name NuGet.Core -RequiredVersion 2.9.0 -ProviderName NuGet -Path C:\LocalPkg
Name Version Source Summary
---- ------- ------ -------
Microsoft.Web.Xdt 3.0.0 Nuget Microsoft Xml Document Transformation (XDT) enables...
NuGet.Core 2.9.0 Nuget NuGet.Core is the core framework assembly for NuGet...
Save-Package
會使用 Name 參數來指定封裝。 RequiredVersion 指出特定的套件版本。 套件會從 ProviderName 參數指定的存放庫下載。 Path參數會決定儲存封裝的位置。
範例 3:使用Find-Package來儲存套件
此命令會使用 Find-Package
來尋找最新版本的套件,並將 物件傳送至 Save-Package
。
PS> Find-Package -Name NuGet.Core -ProviderName NuGet | Save-Package -Path C:\LocalPkg
Find-Package
會使用 Name 參數來指定封裝。 套件會從 ProviderName 參數指定的存放庫下載。 物件會向下傳送至 Save-Package
管線。 Path參數會決定儲存封裝的位置。
範例 4:儲存並安裝套件
最新版本的套件及其相依性會下載並安裝在本機電腦上。
PS> Save-Package -Name NuGet.Core -ProviderName NuGet -Path C:\LocalPkg
PS> Install-Package C:\LocalPkg\NuGet.Core.2.14.0.nupkg
Save-Package
會將套件檔案及其相依性下載到本機電腦。
Install-Package
會從指定的目錄安裝套件和相依性。
參數
-AcceptLicense
如果套件需要授權合約,請在安裝期間自動接受授權合約。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-AllowPrereleaseVersions
允許將標示為發行前版本的套件儲存。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-AllVersions
指出此 Cmdlet 會儲存套件的所有可用版本。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Command
指定封裝中包含的一或多個命令。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ConfigFile
指定組態檔。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Confirm
在執行 Cmdlet 前提示您確認。
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Contains
Save-Package
如果物件屬性值中的任何專案與指定的值完全相符,就會取得 物件。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Credential
指定具有從指定封裝提供者或來源儲存封裝之許可權的使用者帳戶。
Type: | PSCredential |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DscResource
指定封裝的一或多個Desired State Configuration (DSC) 資源。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Filter
指定封裝的篩選準則。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-FilterOnTag
指定篩選結果的標記。 排除不包含指定標籤的結果。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Force
強制執行命令而不要求使用者確認。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ForceBootstrap
表示 Save-Package
強制 PackageManagement 自動安裝指定套件的套件提供者。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Headers
指定封裝的標頭。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Includes
指出套件所包含的資源。
Type: | String[] |
Accepted values: | DscResource, Cmdlet, Function, Workflow, RoleCapability |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-InputObject
代表您要儲存之套件的軟體識別碼物件。 軟體識別碼是 Cmdlet 結果的 Find-Package
一部分。
Type: | Microsoft.PackageManagement.Packaging.SoftwareIdentity |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-LiteralPath
指定您要儲存封裝的常值路徑。 您無法將此參數和 Path 參數新增至相同的命令。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-MaximumVersion
指定您要儲存的套件版本上限。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-MinimumVersion
指定您想要尋找之套件的最低版本。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Name
指定一或多個封裝名稱。
Type: | String[] |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-PackageManagementProvider
指定套件管理提供者。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Path
指定要儲存封裝之本機電腦上的位置。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ProviderName
指定一或多個提供者名稱。
Type: | String[] |
Aliases: | Provider |
Accepted values: | Bootstrap, NuGet, PowerShellGet |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Proxy
指定要求的 Proxy 伺服器,而不是直接連線到網際網路資源。
Type: | Uri |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ProxyCredential
指定具有使用 Proxy 參數所指定 Proxy 伺服器之權限的使用者帳戶。
Type: | PSCredential |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-PublishLocation
指定發行位置。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-RequiredVersion
指定要儲存的套件確切版本。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-RoleCapability
指定角色功能的陣列。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ScriptPublishLocation
指定腳本發佈位置。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ScriptSourceLocation
指定腳本來源位置。
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-SkipValidate
略過驗證封裝認證的參數。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Source
指定一或多個套件來源。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Tag
指定要在套件中繼資料內搜尋的標記。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Type
指定是否要搜尋具有模組、腳本或任一專案的套件。
Type: | String |
Accepted values: | Module, Script, All |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
顯示執行 Cmdlet 後會發生的情況。 Cmdlet 並不會執行。
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
輸入
Microsoft.PackageManagement.Packaging.SoftwareIdentity
您可以使用管線將 SoftwareIdentity 物件傳送至此 Cmdlet。
輸出
None
此 Cmdlet 不會傳回任何輸出。
備註
重要
從 2020 年 4 月起,PowerShell 資源庫已不再支援傳輸層安全性 (TLS) 1.0 和 1.1 版。 如果您不是使用 TLS 1.2 或更高版本,您在嘗試存取 PowerShell 資源庫時將會收到錯誤。 使用下列命令來確保您使用的是 TLS 1.2:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
如需詳細資訊,請參閱 PowerShell 部落格中的公告 \(英文\)。