dotnet nuget pushdotnet nuget push

本文适用于: ✔️ .NET Core 2.x SDK 及更高版本This article applies to: ✔️ .NET Core 2.x SDK and later versions

“属性”Name

dotnet nuget push - 将包推送到服务器,并将其发布。dotnet nuget push - Pushes a package to the server and publishes it.

摘要Synopsis

dotnet nuget push [<ROOT>] [-d|--disable-buffering] [--force-english-output]
    [--interactive] [-k|--api-key <API_KEY>] [-n|--no-symbols true]
    [--no-service-endpoint] [-s|--source <SOURCE>] [--skip-duplicate]
    [-sk|--symbol-api-key <API_KEY>] [-ss|--symbol-source <SOURCE>]
    [-t|--timeout <TIMEOUT>]

dotnet nuget push -h|--help

描述Description

dotnet nuget push 将包推送到服务器,并将其发布。The dotnet nuget push command pushes a package to the server and publishes it. push 命令使用在系统的 NuGet 配置文件或配置文件链中找到的服务器和凭据详细信息。The push command uses server and credential details found in the system's NuGet config file or chain of config files. 有关配置文件的详细信息,请参阅 Configuring NuGet Behavior(配置 NuGet 行为)。For more information on config files, see Configuring NuGet Behavior. 通过加载 %AppData%\NuGet\NuGet.config (Windows) 或 $HOME/.local/share (Linux/macOS) 获得 NuGet 的默认配置,然后加载任意 nuget.config.nuget\nuget.config,从驱动器的根目录开始,并在当前目录中结束。NuGet's default configuration is obtained by loading %AppData%\NuGet\NuGet.config (Windows) or $HOME/.local/share (Linux/macOS), then loading any nuget.config or .nuget\nuget.config starting from the root of drive and ending in the current directory.

命令推送现有包。The command pushes an existing package. 它不会创建包。It doesn't create a package. 若要创建包,请使用 dotnet packTo create a package, use dotnet pack.

自变量Arguments

  • ROOT

    指定要推送的包的文件路径。Specifies the file path to the package to be pushed.

选项Options

  • -d|--disable-buffering

    当推送到 HTTP(S) 服务器以减少内存使用率时,禁用缓冲。Disables buffering when pushing to an HTTP(S) server to reduce memory usage.

  • --force-english-output

    使用固定的、基于英语的区域性强制运行应用程序。Forces the application to run using an invariant, English-based culture.

  • -h|--help

    打印出有关命令的简短帮助。Prints out a short help for the command.

  • --interactive

    对于身份验证等操作,允许命令阻止并要求手动操作。Allows the command to block and requires manual action for operations like authentication. 自 .NET Core 2.2 SDK 起可用的选项。Option available since .NET Core 2.2 SDK.

  • -k|--api-key <API_KEY>

    服务器的 API 密钥。The API key for the server.

  • -n|--no-symbols true

    不推送符号(即使存在)。Doesn't push symbols (even if present).

  • --no-service-endpoint

    不将“api/v2/package”追加至源 URL。Doesn't append "api/v2/package" to the source URL. 自 .NET Core 2.1 SDK 起可用的选项。Option available since .NET Core 2.1 SDK.

  • -s|--source <SOURCE>

    指定服务器 URL。Specifies the server URL. 除非在 NuGet 配置文件中设置了 DefaultPushSource 配置值,否则此选项是必需的。This option is required unless DefaultPushSource config value is set in the NuGet config file.

  • --skip-duplicate

    将多个包推送到 HTTP(S) 服务器时,将任何 409 冲突响应视为警告,以便可以继续推送。When pushing multiple packages to an HTTP(S) server, treats any 409 Conflict response as a warning so that the push can continue. 自 .NET Core 3.1 SDK 起可用。Available since .NET Core 3.1 SDK.

  • -sk|--symbol-api-key <API_KEY>

    符号服务器的 API 密钥。The API key for the symbol server.

  • -ss|--symbol-source <SOURCE>

    指定符号服务器 URL。Specifies the symbol server URL.

  • -t|--timeout <TIMEOUT>

    指定推送到服务器的超时(秒)。Specifies the timeout for pushing to a server in seconds. 默认值为 300 秒(5 分钟)。Defaults to 300 seconds (5 minutes). 指定为 0(零秒)将应用默认值。Specifying 0 (zero seconds) applies the default value.

示例Examples

  • 将 foo.nupkg 推送到默认推送源(指定 API 密钥) :Push foo.nupkg to the default push source, specifying an API key:

    dotnet nuget push foo.nupkg -k 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a
    
  • 将 foo.nupkg 推送到官方 NuGet 服务器,以指定 API 密钥:Push foo.nupkg to the official NuGet server, specifying an API key:

    dotnet nuget push foo.nupkg -k 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a -s https://api.nuget.org/v3/index.json
    
    • 将 foo.nupkg 推送到自定义推送源 https://customsource(指定 API 密钥) :Push foo.nupkg to the custom push source https://customsource, specifying an API key:
    dotnet nuget push foo.nupkg -k 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a -s https://customsource/
    
  • 将 foo.nupkg 推送到默认推送源 :Push foo.nupkg to the default push source:

    dotnet nuget push foo.nupkg
    
  • 将 foo.symbols.nupkg 推送到默认符号源 :Push foo.symbols.nupkg to the default symbols source:

    dotnet nuget push foo.symbols.nupkg
    
  • 将 foo.nupkg 推送到默认推送源(指定 360 秒超时) :Push foo.nupkg to the default push source, specifying a 360-second timeout:

    dotnet nuget push foo.nupkg --timeout 360
    
  • 将当前目录中的所有 .nupkg 文件推送到默认推送源 :Push all .nupkg files in the current directory to the default push source:

    dotnet nuget push "*.nupkg"
    

    备注

    如果此命令不起作用,则可能是较旧版本的 SDK(.NET Core 2.1 SDK 及更早版本)中的 bug 导致的。If this command doesn't work, it might be due to a bug that existed in older versions of the SDK (.NET Core 2.1 SDK and earlier versions). 要解决此问题,请升级 SDK 版本或改为运行以下命令:dotnet nuget push "**/*.nupkg"To fix this, upgrade your SDK version or run the following command instead: dotnet nuget push "**/*.nupkg"

    备注

    用于执行文件组合的 bash 等 shell 需要用引号括起来。The enclosing quotes are required for shells such as bash that perform file globbing. 有关详细信息,请参阅 NuGet/Home#4393For more information, see NuGet/Home#4393.

  • 推送所有 .nupkg 文件,即使 HTTP(S) 服务器返回了 409 冲突响应也是如此 :Push all .nupkg files even if a 409 Conflict response is returned by an HTTP(S) server:

    dotnet nuget push "*.nupkg" --skip-duplicate
    
  • 将当前目录中的所有 .nupkg 文件推送到本地源目录 :Push all .nupkg files in the current directory to a local feed directory:

    dotnet nuget push "*.nupkg" -s c:\mydir
    

    此命令不会将包存储在分层文件夹结构中,因此建议优化性能。This command doesn't store packages in a hierarchical folder structure, which is recommended to optimize performance. 有关详细信息,请参阅本地源For more information, see Local feeds.