3

I am trying to build my dotnet class library project via GitHub Actions. My project uses a private NuGet package stored on the GPR in addition to some standard nuget.org packages. I have not been able to get a successful build like I have on my local machine.

I am using setup-dotnet (and have tried warrenbuckley/Setup-Nuget, but no luck):

jobs:
  build:
    runs-on: windows-latest # I started with ubuntu-latest, but the dotnet nuget is missing functionality.
    steps:
      - uses: actions/checkout@master
      - uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '3.1.100'
          source-url: https://nuget.pkg.github.com/owner/index.json
        env:
          NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
      - run: dotnet restore --source # fails here
      - run: dotnet build -c Release --no-restore

I know it finds the proper GPR because here it successfully installs my private packages, but fails to find any of the nuget.org pacakges.
Another variation I've tried:

      - run: dotnet nuget add source https://nuget.pkg.github.com/myorg/index.json -n "My Source"
      - run: dotnet build -c Release --no-restore # fails here

Here, it cannot find my private pacakges.
Recently, I've tried the nuget cli:

      - uses: warrenbuckley/Setup-Nuget@v1
      - run: nuget sources Add -Source https://nuget.pkg.github.com/myorg/index.json -Name "My Org" -username myorguser -password ${{secrets.GITHUB_TOKEN}} -StorePasswordInClearText
      - run: nuget restore # Fails here
      - run: dotnet build -c Release --no-restore

This gives the most information, but still fails to find my GPR packages, even though (unlike the previous examples) it finds all the sources I would expect (local, nuget.org, and my private org). Here are some of the logs that seem interesting:

32 NotFound https://nuget.pkg.github.com/myorg/download/mypackage/index.json
...
65 NotFound https://api.nuget.org/v3-flatcontainer/efinitycore/index.json
...
930     NU1101: Unable to find package MyPackage. No packages exist with this id in source(s): My Org, Microsoft Visual Studio Offline Packages, nuget.org
931 Errors in D:\a\WorkflowLibrary\WorkflowLibrary\WorkflowLibrary.Tests\WorkflowLibrary.Tests.csproj
932     NU1101: Unable to find package MyPackage. No packages exist with this id in source(s): My Org, Microsoft Visual Studio Offline Packages, nuget.org
...
935 NuGet Config files used:
    C:\Users\runneradmin\AppData\Roaming\NuGet\NuGet.Config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
    C:\Program Files (x86)\NuGet\Config\Xamarin.Offline.config

942 Feeds used:
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
    https://api.nuget.org/v3/index.json
    https://nuget.pkg.github.com/myorg/index.json
Connor Low
  • 5,900
  • 3
  • 31
  • 52

3 Answers3

2

This worked for me

jobs: build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Setup Nuget.exe
  uses: nuget/setup-nuget@v1.0.2
- name: Add GPR Source using nuget.exe
  run: nuget sources add -name "GPR" -Source https://api.nuget.org/v3/index.json -Source https://nuget.pkg.github.com/{myorg}/index.json -Username {login} -Password ${{ token }}
- name: Setup .NET Core
  uses: actions/setup-dotnet@v1
  with:
    dotnet-version: 3.1.101
0
steps:
      - uses: actions/checkout@master
      - uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '3.1.100'
          source-url: https://nuget.pkg.github.com/owner/index.json
        env:
          NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

In above step, change NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} to NUGET_AUTH_TOKEN: ${{secrets.YOUR_PAT}}. I faced the same problem and I was able to access my GPR private feed with PAT.

Pradeep
  • 3,258
  • 1
  • 23
  • 36
  • Thanks, but this is not my issue. It's not finding my package source and the NuGet source at the same time (404), but authentication works fine when it does. – Connor Low Feb 01 '21 at 16:09
  • Hello, I downvoted because this doesn't answer the question. The question is about about how to add multiple sources, not how to authenticate. – jschmitter Feb 07 '22 at 18:20
0

Just spent half a day on the problem similar to what OP describes. One has to pay attention to the cross-repository scenario where packages originate/are built in one repository and then are attempted to be restored via GH Actions in another repository. Under that scenario the GITHUB_TOKEN generated by Actions is scoped to the current repo and has no permissions to see packages from other private repos within the GH org. This results in Nuget showing NotFound response codes when attempting to check for packages in GPR and, eventually, the NU1101 error code.

More info here on the underlying problem: https://github.community/t/github-token-cannot-access-private-packages/16621/14

The sorry workaround is to switch to using Personal Access Tokens.

V. Orekhov
  • 11
  • 1