运行 dotnet restore 时如何使用私有 nuget 包源进行身份验证

How to authenticate with private nuget package source while running dotnet restore

我正在尝试 运行 dotnet restore --configfile NuGet.config my-solution.sln 在命令行上从私有 nuget 源恢复包,但我无法使用私有 nuget 进行身份验证,我收到此错误:

Retrying 'FindPackagesByIdAsyncCore' for source 'http://my.private.nuget/source/FindPackagesById()?semVerLevel=2.0.0'.
Response status code does not indicate success: 401 (Unauthorized).

然而,当我尝试从 visual studio 恢复 nuget 包时,我能够成功地从 visual studio 恢复包,我收到一个提示要求提供凭据,并且在添加凭据后恢复正确。

我试图弄清楚在通过命令行恢复时我需要在哪里添加私有 nuget 的凭据。

我通过在 Nuget.config 文件中添加我的 nuget 凭据解决了这个问题,参考这个 link 查看如何正确设置 Nuget.config 文件的格式,如 nuget 4.6 和下面的格式,用于将凭据添加到 Nuget.config 的格式与新版本的格式不同。