Using the .NET CLI to restore packages from a private NuGet feed
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
标签:feed,restore,CLI,nuget,NuGet,dotnet,install,Project From: https://www.cnblogs.com/chucklu/p/16734108.html