'dotnet restore in Github Actions gives 401 unauthorized

a NET6 project on Github cannot be dotnet-restored in Github Actions. dotnet restore works fine locally. Looking at the Action logs, it seems GH looks for Microsoft dependencies in my Github Packages Repo. System.Linq is MS-stuff.

  Retrying 'FindPackagesByIdAsync' for source 'https://nuget.pkg.github.com/mdddev/download/system.linq/index.json'.
  Response status code does not indicate success: 401 (Unauthorized).
/home/runner/.dotnet/sdk/6.0.202/NuGet.targets(130,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured. [/home/runner/work/meh/meh/meh.sln]

Further below in the pipeline there is a step to publish the result to the Github Packages registry, however in the project itself I am only using public NUGET references. I am not sure why GH Actions looks for the NET stuff in my registry. I even have the public Nuget feed configured in my nuget.config:

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

Does anyone know what;s the problem here?



Solution 1:[1]

You are using GitHub packages here, you have to authenticate yourself.
for more info -> https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry#authenticating-with-a-personal-access-token

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manish