问题
Pushing a Nuget package to Azure Artifacts always gives 401 error. Note that the API key was just copied from Azure portal. What could be the issue?
dotnet nuget push out/MonoTorrent.1.0.39.nupkg -s "myfeed" -k "myapikey"
Output:
Pushing MonoTorrent.1.0.39.nupkg to 'https://pkgs.dev.azure.com/myacct/c7fc868d-fd14-4f27-a36a-8ff9add6482c/_packaging/c2fe5b0f-251b-4017-9848-ed4b906d9fc0/nuget/v2/'...
PUT https://pkgs.dev.azure.com/myacct/c7fc868d-fd14-4f27-a36a-8ff9add6482c/_packaging/c2fe5b0f-251b-4017-9848-ed4b906d9fc0/nuget/v2/
Unauthorized https://pkgs.dev.azure.com/myacct/c7fc868d-fd14-4f27-a36a-8ff9add6482c/_packaging/c2fe5b0f-251b-4017-9848-ed4b906d9fc0/nuget/v2/ 1248ms
error: Response status code does not indicate success: 401 (Unauthorized).
Nuget.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="myfeed" value="https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json" />
</packageSources>
<myfeed>
<add key="Username" value="myliveidemail" />
<add key="ClearTextPassword" value="myapikey" />
</myfeed>
</configuration>
回答1:
1.Looks like you're trying to add the credentials into Nuget.config
file, this is not recommended because:
We strongly recommend not checking your PAT into source control. Anyone with access to your PAT can gain access to your Azure DevOps Services.
Though it's not recommended, it should work. For me I use command like:
dotnet nuget push --source "myfeed" --api-key az Test.1.0.0.nupkg
And the Nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="myfeed" value="https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<myfeed>
<add key="Username" value="lancel" />
<add key="ClearTextPassword" value="YourPat, instead of the APIkey" />
</myfeed>
</packageSourceCredentials>
</configuration>
It means you'll need to create PAT which is scoped to the organization(s) you want to access with following permissions: Packaging (read), Packaging (read and write), or Packaging (read, write, and manage).
Then it should be <add key="ClearTextPassword" value="%PAT%" />
.
2.And another direction is to use Azure Artifacts Credential Provider in non-interactive scenarios.
Run the helper script to install it automatically and set a VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
variable. The value of this variable should be:
{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json", "password":"PAT"}]}
来源:https://stackoverflow.com/questions/61672671/azure-artifacts-gives-401-error-on-publishing-a-nuget-package