question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet nuget push fails to authenticate

See original GitHub issue

Description

I can’t get authentication to work after reading the README section and related issues (https://github.com/NuGet/Home/issues/8580#issuecomment-599056152).

I want to:

  1. restore dependencies from nuget.org
  2. publish a package to GPR

Details

I have a nuget.config in my repo with just the source I need to restore dependencies.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Then I added the bit of yaml that configures the GPR source-url and adds authentication.

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-dotnet@v1
      with:
        source-url: https://nuget.pkg.github.com/stevenliekens/index.json
      env:
        NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    - run: dotnet pack --configuration Release --output artifacts --version-suffix CI-$(date --utc '+%Y%m%d-%H%M%S')
    - run: dotnet nuget push artifacts/*.nupkg

No matter what I do, I get an error on the last step saying that my API key is missing.

warn : No API Key was provided and no API Key could be found for ‘https://nuget.pkg.github.com/stevenliekens’. To save an API Key for a source use the ‘setApiKey’ command.

Can this be a bug in the action? I don’t see what I could possibly be missing.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ZEisingercommented, Sep 3, 2020

It seems the original problem with not using the given token would be solved by #109 (not released in v1 yet). The nuget file was being generated into a temp folder outside the repo path and was not being used.

0reactions
sliekenscommented, Apr 2, 2021

My conclusion is that you have to do one of two things:

  • A) Remove the <clear /> element from your nuget.config
  • B) Add the source that requires authentication to your nuget.config

So this will never work:

    - uses: actions/setup-dotnet@v1
      with:
        config-file: nuget.config
        source-url: https://nuget.pkg.github.com/OwnerName/index.json
      env:
        NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
<!-- Will never work, even though the NUGET_AUTH_TOKEN is added, it can't be matched to a packageSource after the <clear/> -->
<configuration>
    <packageSources>
        <clear />
        <add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    </packageSources>
</configuration>

Option A:

<!-- Will work because packageSources are now merged with the temporary nuget.config in the parent directory -->
<configuration>
    <packageSources>
        <add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    </packageSources>
</configuration>

Option B:

<!-- Will also work because setup-dotnet will match your existing packageSource -->
<configuration>
    <packageSources>
        <clear />
        <add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
        <add key="gh" value="https://nuget.pkg.github.com/OwnerName/index.json" protocolVersion="3" />
    </packageSources>
</configuration>
Read more comments on GitHub >

github_iconTop Results From Across the Web

nuget push to artifacts from build script fails to authenticate
I've got the YAML to trigger and run the build, and it builds but fails to push the artifacts into the nuget repository....
Read more >
Unauthorized error when trying to push nuget package to ...
The dotnet nuget push command pushes a package to the server and publishes it. The push command uses server and credential details found...
Read more >
Why do nuget push commands authenticate yet still return a ...
When performing a nuget push command, you notice your command ultimately fails due to a 401 response even though the repository manager request...
Read more >
NuGetAuthenticate@1 - NuGet authenticate v1 task
This task configures nuget.exe, dotnet, and MSBuild to authenticate with Azure Artifacts or other repositories that require authentication.
Read more >
Pushing to MyGet from VSTS fails with "Forbidden"
Symptoms · Cause and solution · 1) Make sure the feed you are using is in NuGet. · 2) In VSTS, configure two...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found