Save-Package
将包保存到本地计算机,而无需安装它们。
语法
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>]
说明
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
表示要保存的包的软件 ID 对象。 软件 ID 是 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
指定请求的代理服务器,而不是与 Internet 资源的直接连接。
Type: | Uri |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-ProxyCredential
指定有权使用由 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 博客中的公告。