I am attempting to make available a .NET Framework v4.5.2 package in Visual Studio 2019, via NuGet Package Manager, and sourced from Github's private NuGet package registry system.
Important Stuff I'm Using:
- .NET Framework 4.5.2
- Github Actions
- Github
- Github Package Registry (GPR)
- Visual Studio 2019/NuGet Package Manager
What Is My Goal?
The whole lifecycle looks a bit like this:
- My project's repo has a CI job (Github brand) to
msbuild
& publishnupkg
. It wraps everything up and deploys it to https://nuget.pkg.github.com/< my-private-org >. - In Visual Studio 2019, with a given project cracked open, a user should be able to reference https://nuget.pkg.github.com/< my-private-org > as a custom NuGet feed, and declare "My Project" as a dependency.
What Works, What Doesn't?
GitHub successfully publishes my package--I can see it when I visit https://github.com/my-private-organization?tab=packages.
However, I cannot make Visual Studio 2019 support my private NuGet registry. When I attempt to access it, I get the error:
[Private] Failed to retrieve metadata from source 'https://nuget.pkg.github.com/<my-private-organization>/query?q=&skip=0&take=26&prerelease=true&supportedFramework=.NETFramework,Version=v4.7&semVerLevel=2.0.0'.
Response status code does not indicate success: 401 (Unauthorized).
When I attempt to run the same query (GET https://nuget.pkg.github.com/<my-private-organization>/query?q=&skip=0&take=26&prerelease=true&supportedFramework=.NETFramework,Version=v4.7&semVerLevel=2.0.0'
) in the browser, I am prompted with a modal to enter my GitHub credentials, but after entering them, I am met with the same 401, but a different error message:
{
"errors": [
{
"code" : "Your token has not been granted the required scopes to execute this query. The 'id' field requires one of the following scopes",
"message":" ['read:packages'], but your token has only been granted the: [''] scopes. Please modify your token's scopes at: https://github.com/settings/tokens."
}
]
}
I definitely have a GITHUB_TOKEN
with read:package
perms--I used it to generate the package in the first place in my CI job.
I am suspicious that...
I need to pass my read:package
credentialed GITHUB_TOKEN
as extra auth-credentials, but I don't know if/how I can configure that in nuget.config
. Which leads us to...
What is my configuration?
I read that I need to parameterize my %APPDATA%/NuGet/nuget.config
with some extra credential information, which I got from here: https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#packagesourcecredentials. I can confirm that I'm updating the correct nuget.config
file--I've been able to change package stream names in Visual Studio with the file I'm touching. It now looks a bit like:
<!-- file: nuget.config -->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Private" value="https://nuget.pkg.github.com/###############/index.json" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
</packageSources>
<packageSourceCredentials>
<Private>
<add key="Username" value="###############" />
<add key="ClearTextPassword" value="*******************" />
<!-- Could I perhaps need to introduce my Github Access Token here? -->
</Private>
</packageSourceCredentials>
</configuration>
The username and password specified in packageSourceCredentials
are the same I used in the manual GET
query done in the browser (which failed in a 401).
All thoughts are welcome, even "Nobody Does A".