Using the .NET CLI to restore packages from a private NuGet feed error NU1301: Unable to load the service index for source
Using the .NET CLI to restore packages from a private NuGet feed error NU1301: Unable to load the service index for source
For the past years, I've been working in Visual Studio (the 2022 preview version is available), but recently I've given Visual Studio Code a shot. Transitioning between the two IDE's also means that you use the .NET CLI more extensively. Sadly, this was the cause of one annoying problem for me.
A couple of times a day, when I was trying to build a project, I bumped against the following error saying that I'm not authorized to access our private feed.
This led to frustrations and was counter-productive. As a work-around, I opened the project in Visual Studio to be authorized.
Some GitHub issues mentioned running the restore command with the interactive flag, but in my case, this ended up in the same error.
After browsing through more GitHub issues, I found a comment that suggested installing the Microsoft NuGet CredentialProvider.
To my satisfaction, the error was finally gone.
Support me
I appreciate it if you would support me if have you enjoyed this post and found it useful, thank you in advance.
https://github.com/Microsoft/artifacts-credprovider#setup
Setup
If you are using dotnet
or nuget
, you can use the Azure Artifact Credential Provider by adding it to NuGet's plugin search path. This section contains both manual and scripted instructions for doing so.
Dotnet needs the netcore
version to be installed. NuGet and MSBuild need the netfx
version to be installed.
Installation on Windows
Automatic PowerShell script
- To install netcore, run
installcredprovider.ps1
- e.g.
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }"
- e.g.
- To install both netfx and netcore, run
installcredprovider.ps1 -AddNetfx
. The netfx version is needed for nuget.exe.- e.g.
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"
- e.g.
Manual installation on Windows
- Download the latest release of Microsoft.NuGet.CredentialProvider.zip
- Unzip the file
- Copy the
netcore
(andnetfx
for nuget.exe) directory from the extracted archive to$env:UserProfile\.nuget\plugins
(%UserProfile%/.nuget/plugins/)
Using the above is recommended, but as per NuGet's plugin discovery rules, alternatively you can install the credential provider to a location you prefer, and then set the environment variable NUGET_PLUGIN_PATHS to the .exe of the credential provider found in plugins\netfx\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe. For example, $env:NUGET_PLUGIN_PATHS="my-alternative-location\CredentialProvider.Microsoft.exe". Note that if you are using both nuget and dotnet, this environment variable is not recommended due to this issue: NuGet/Home#8151
Azure DevOps Artifacts authentication issues · NuGet/Home Wiki · GitHub
命令行需要安装参考这个
Command line credential provider not installed
如果是visual studio使用中遇到这个问题的话,可能是账号的token过期了
Account session has expired
If you open Visual Studio's Account Settings window, any account with expired credentials will have a message saying that the credentials need to be refreshed.
Additional recommendations 实际测试,还是这个有效
If the above has not helped, additional things to try include:
- Sign out of all accounts
- Close VS
- Restart VS
- Open VS
- Sign into your account in Visual Studio again.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2017-09-27 2>&1
2017-09-27 powershell输出错误信息到文件
2016-09-27 Have You Ever Wondered About the Difference Between NOT NULL and DEFAULT?
2016-09-27 Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
2015-09-27 积分
2015-09-27 Playing with cubes II
2015-09-27 Smallest unused ID