使用 NuGetCommand@2 将包推送到 nuget.org

Use NuGetCommand@2 to push packages to nuget.org

documentation here

To publish to an external NuGet feed, you must first create a service connection to point to that feed....

然后它提供这个 YAML:

- task: NuGetAuthenticate@0
  inputs:
    nuGetServiceConnections: '<Name of the NuGet service connection>'
- task: NuGetCommand@2
  inputs:
    command: push
    nuGetFeedType: external
    versioningScheme: byEnvVar
    versionEnvVar: <VersionVariableName>

这失败了

"Error: The service connection for 'https://api.nuget.org/v3/index.json' is not valid. ApiKey service connections are not supported in this task. Instead, use -ApiKey (NuGet) or --api-key (dotnet) when invoking the tool itself. See the task documentation for more details."

我已经使用我的 ApiKey 创建了指向 nuget.org 的服务连接。

我不理解错误消息的这一部分:“而是在调用工具本身时使用 -ApiKey (NuGet) 或 --api-key (dotnet)。有关更多信息,请参阅任务文档详情。

我也看到了,它指的是一个已经实施的缺陷。

编辑:原来上面提到的缺陷是一个转移注意力的问题。真正的问题是 nuget 的限制,在撰写本文时仍然存在。

根据 NuGet Authenticate task document:

Some package sources such as nuget.org use API keys for authentication when pushing packages, rather than username/password credentials. Due to limitations in NuGet, this task cannot be used to set up a NuGet service connection that uses an API key.

Instead:

  1. Configure a secret variable containing the ApiKey

  2. Perform the package push using nuget push -ApiKey $(myNuGetApiKey) or dotnet nuget push --api-key $(myNuGetApiKey), assuming you named the variable myNuGetApiKey