首页 > 其他分享 >Using the .NET CLI to restore packages from a private NuGet feed

Using the .NET CLI to restore packages from a private NuGet feed

时间:2022-09-27 12:13:11浏览次数:71  
标签:feed restore CLI nuget NuGet dotnet install Project

Using the .NET CLI to restore packages from a private NuGet feed

  @tim_deschryver
All posts

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

PowerShell helper script

  • To install netcore, run installcredprovider.ps1
    • e.g. iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }"
  • 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"

Manual installation on Windows

  1. Download the latest release of Microsoft.NuGet.CredentialProvider.zip
  2. Unzip the file
  3. Copy the netcore (and netfx 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

相关文章