使用NuGet发布和使用GitHub软件包存储库:无法加载服务索引错误 [英] Publishing and Consuming GitHub Package Repository with NuGet: Unable to load the service index error

查看:132
本文介绍了使用NuGet发布和使用GitHub软件包存储库:无法加载服务索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GitHub软件包推送并使用NuGet软件包(

I'm trying to push and then consume a NuGet package using GitHub packages (documentation here). As a newcomer, after experimenting a bit I managed to push a sample NuGet package to a public GitHub repository.

但是,我缺少最后一部分,即使用某些Visual Studio项目中的包.当我尝试添加程序包时,首先收到正在还原程序包..."通知,然后出现错误无法加载源程序的服务索引...":输入不是有效的Base-64字符串,例如它包含一个非基本的64个字符,两个以上的填充字符或填充字符中的非法字符."

Yet, I'm missing the final part, i.e. consume the package from some Visual Studio project. When I try to add the package, I first get a "Restoring packages for..." notification, and then the error "Unable to load the service index for source... : The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters".

因此,看来我的NuGet端点未按预期配置,但我找不到关于此的明确方向.为了帮助像我这样的新手从GPR开始,并详细说明我的程序,以便读者发现我的错误,这是我到目前为止所学到的:

So, it seems my endpoint for NuGet is not configured as expected, yet I could not find a clear direction about this. To help newbies like me starting with GPR, and detail my procedure so that readers can spot my errors, here is what I learnt until now:

在使用GPR之前,您必须在您的GitHub帐户中创建令牌.

Before using GPR, you must create a token in your GitHub account.

  1. 分别将 .csproj 文件中的 RepositoryUrl RepositoryType 属性设置为目标存储库URL和 git ,例如:
  1. set the RepositoryUrl and RepositoryType properties in your .csproj file to your target repository URL and git respectively, e.g.:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <!-- omissis ... -->
    <RepositoryUrl>https://github.com/USERNAME/PROJECTNAME</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
  </PropertyGroup>
</Project>

  1. 在您的项目文件夹中打开GitHub bash,然后像这样创建包:

dotnet pack NAME.csproj -c Release -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg

其中 -c 选择配置.请参阅创建snupkg,以及 dotnet包参考.

where -c selects the configuration. See creating snupkg for more, and the dotnet pack reference.

  1. 在项目文件夹中打开GitHub bash,并发布,如下所示: dotnet nuget push"bin/Release/NAME.1.0.0.nupkg" --source"github" .
  1. open the GitHub bash in your project folder, and publish like this: dotnet nuget push "bin/Release/NAME.1.0.0.nupkg" --source "github".

注意:您首先需要向GPR供稿注册(一次):

Note: you first need to register (once) the GPR feed with:

nuget sources add -name "github" -Source https://nuget.pkg.github.com/YOURGITHUBUSERNAME/index.json -Username YOURGITHUBUSERNAME -Password YOURGITHUBTOKEN

如果您需要安装 nuget.exe ,请从 https://www下载..nu​​get.org/downloads .如果您将其放置在在 C:\ Exe 中,您可以使用/c/Exe/nuget.exe 从Windows Git Bash调用它.

If you need to install nuget.exe, download it from https://www.nuget.org/downloads. If you place it e.g. in C:\Exe, you can invoke it from the Windows Git Bash with /c/Exe/nuget.exe.

此外,您需要设置nuget API密钥:

Also, you need to set the nuget API key:

nuget setapikey YOURGITHUBTOKEN -Source https://nuget.pkg.github.com/YOURGITHUBUSERNAME/index.json

这会加密密钥并将其保存在%APPDATA%文件夹下的配置文件中.例如我的结束于 C:\ Users \ USERNAME \ AppData \ Roaming \ NuGet \ NuGet.Config .

This encrypts the key and saves it in a config file under your %APPDATA% folder. e.g. mine ends up in C:\Users\USERNAME\AppData\Roaming\NuGet\NuGet.Config.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆