Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credential Provider Not Found at Default Path on Linux #68

Open
twinter-amosfivesix opened this issue Jan 19, 2023 · 1 comment
Open

Comments

@twinter-amosfivesix
Copy link

TLDR:

This line in NugetLightRequest.GetCredsFromCredProvider incorrectly uses $HOME instead of %HOME% as required by Environment.ExpandEnvironmentVariable(). This causes the credential provider to not be found

// If running Unix
path = "$HOME/.nuget/plugins/netcore/CredentialProvider.Microsoft/CredentialProvider.Microsoft.dll";

Longer Version

Running Red Hat Enterprise Linux release 8.7, PowerShell 7.3.1, PackageManagement 1.4.8.1, PowerShellGet 2.2.5.

Trying to use an Azure Artifacts feed with PowerShell. Installed the credential provider, setup my PS-Repository, etc. (Got all this working on Windows no problem).

When I run Install-Module ModuleFromMyFeed -Debug I get output that includes this:

DEBUG: 00:00:01.3022327 Calling 'GetCredsFromCredProvider' on https://pkgs.dev.azure.com:443/myorg/_packaging/myfeed/nuget/v2/FindPackagesById()?id='ModuleFromMyFeed'&$skip=%7B0%7D&$top=%7B1%7D
DEBUG: 00:00:01.3028816 Calling credential provider installed at
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET program, but dotnet--V does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

Note the line for Calling credential provider installed at. There is nothing listed after the at. And note how dotnet thinks I'm trying to run dotnet --V.

If you read through the code in NugetLightRequest.GetCredsFromCredProvider you'll see it first looks for NUGET_PLUGIN_PATHS, which I do not have defined. That fails so it tries to look for the provider at "$HOME/.nuget/plugins/netcore/CredentialProvider.Microsoft/CredentialProvider.Microsoft.dll". It passes that string to Environment.ExpandEnvironmentVariables(). But does not work. Because Environment.ExpandEnvironmentVariables expects variables to be in the format %VAR%, not $VAR. See this github issue. So the variable is not expanded, so the File.Exists() check fails. That leaves credProviderPath blank, so the code then tries to run dotnet -V verbose -U <url>. Which gives the error we see in the output.

The Fix

In the source code switch $HOME to %HOME%.

The workaround.

Set the environment variable NUGET_PLUGIN_PATHS to the full path of CredentialProvider.Microsoft.dll. For example, $env:NUGET_PLUGIN_PATHS = "/home/username/.nuget/plugins/netcore/CredentialProvider.Microsoft/CredentialProvider.Microsoft.dll"

This does work for me.

@jachin84
Copy link

jachin84 commented Aug 24, 2023

I ran into this today as well and can confirm @twinter-amosfivesix's findings, fix and workaround. This was extremely difficult to find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants