dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.66k stars 1.06k forks source link

Can not install dotnet-ef through CLI (Unauthorized) #11837

Open Think3wang opened 4 years ago

Think3wang commented 4 years ago

I am trying to install dotnet-ef package through dotnet cli, how ever it gave me 401 (Unauthorized) error.

The command I run is dotnet tool install --global dotnet-ef what I don't understand is, the dotnet-ef is a public package that anyone can install, what is this "authorized" about?

The detailed result I got is :

C:\Program Files\dotnet\sdk\3.1.300\NuGet.targets(128,5): error : Unable to load the service index for source https://microsoft.pkgs.visualstudio.com/_packaging/Universal.Store/nuget/v3/index.json. [C:\Users\<myUserName>\AppData\Local\Temp\wojjcmbm.aon\restore.csproj]
C:\Program Files\dotnet\sdk\3.1.300\NuGet.targets(128,5): error :   Response status code does not indicate success: 401 (Unauthorized). [C:\Users\<myUserName>\AppData\Local\Temp\wojjcmbm.aon\restore.csproj]
joeloff commented 4 years ago

The authentication relates to the package feed it's trying to access. Check your global nuget.config file for that package source and potentially remove it. You can run dotnet nuget list source to see which sources you are using by default.

You can also try to run with --ignore-failed-sources.

RehanSaeed commented 3 years ago

I'm getting the same issue. I'm not using any custom nuget.config files. These are my listed packages. I'm getting this error with .NET 5.0.100.

dotnet nuget list source
Registered Sources:
  1.  nuget.org [Enabled]
      https://api.nuget.org/v3/index.json
  2.  Microsoft Visual Studio Offline Packages [Enabled]
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
gifthove commented 2 years ago

If you have many sources for packages you will need to include " --ignore-failed-sources", that worked for me. dotnet tool install --global dotnet-ef --version 5.0.13 --ignore-failed-sources

prags9 commented 2 years ago

The authentication relates to the package feed it's trying to access. Check your global nuget.config file for that package source and potentially remove it. You can run dotnet nuget list source to see which sources you are using by default.

You can also try to run with --ignore-failed-sources.

I had to add nuget.config file with the following content -

<?xml version="1.0" encoding="utf-8"?>

umerkle commented 11 months ago

The authentication relates to the package feed it's trying to access. Check your global nuget.config file for that package source and potentially remove it. You can run dotnet nuget list source to see which sources you are using by default. You can also try to run with --ignore-failed-sources.

I had to add nuget.config file with the following content -

@prags9 What content? A dash?

deadlydog commented 7 months ago

I had some additional custom sources. Just using --ignore-failed-sources wasn't enough. I went into Visual Studio -> Tools -> Options -> NuGet Package Manager -> Package Sources and unchecked the extra package sources so only nuget.org and Microsoft Visual Studio Offline Packages was left checked. After doing that I was able to install the tool using dotnet tool install dotnet-ef --global --ignore-failed-sources, and then I re-enabled my custom package sources.

markopavic commented 5 months ago

I confirm: --ignore-failed-sources, isn't working, still getting 401 (Unauthorized). I temporarely removed the additional sources from the global nuget config file, then I was able to succesfully run dotnet tool install --global dotnet-ef

CoolDadTx commented 2 months ago

Same issue here. --ignore-failed-sources used to work but somewhere along the way it now fails. I have custom sources and have had to use that flag for years but after updating to NET 8 it doesn't seem to work anymore. Seems like a regression bug.

whiskycompiler commented 2 months ago

Same issue. I get this:

PS C:\Users\whisky\Desktop\test> dotnet --version
8.0.303
PS C:\Users\whisky\Desktop\test> dotnet tool update --global dotnet-ef --ignore-failed-sources
Unhandled exception: System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at NuGet.Protocol.HttpSource.<>c__DisplayClass15_0`1.<<GetAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func`2 action, CancellationToken token)
   at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func`2 action, CancellationToken token)
   at NuGet.Protocol.HttpSource.GetAsync[T](HttpSourceCachedRequest request, Func`2 processAsync, ILogger log, CancellationToken token)
   at NuGet.Protocol.PackageMetadataResourceV3.LoadRegistrationIndexAsync(HttpSource httpSource, Uri registrationUri, String packageId, SourceCacheContext cacheContext, Func`2 processAsync, ILogger log, CancellationToken token)
   at NuGet.Protocol.PackageMetadataResourceV3.GetMetadataAsync(String packageId, Boolean includePrerelease, Boolean includeUnlisted, VersionRange range, SourceCacheContext sourceCacheContext, ILogger log, CancellationToken token)
   at NuGet.Protocol.PackageMetadataResourceV3.GetMetadataAsync(String packageId, Boolean includePrerelease, Boolean includeUnlisted, SourceCacheContext sourceCacheContext, ILogger log, CancellationToken token)
   at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.GetPackageMetadataAsync(PackageSource source, String packageIdentifier, Boolean includePrerelease, Boolean includeUnlisted, CancellationToken cancellationToken)
   at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.GetMatchingVersionInternalAsync(String packageIdentifier, IEnumerable`1 packageSources, VersionRange versionRange, CancellationToken cancellationToken)
   at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.GetBestPackageVersionAsync(PackageId packageId, VersionRange versionRange, PackageSourceLocation packageSourceLocation)
   at Microsoft.DotNet.Cli.ToolPackage.ToolPackageDownloader.<>c__DisplayClass8_0.<InstallPackage>b__0()
   at Microsoft.DotNet.Cli.TransactionalAction.Run[T](Func`1 action, Action commit, Action rollback)
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.<>c__DisplayClass20_0.<Execute>b__1()
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.RunWithHandlingInstallError(Action installAction)
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.Execute()
   at Microsoft.DotNet.Tools.Tool.Update.ToolUpdateGlobalOrToolPathCommand.Execute()
   at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)

The workaround that worked for me:

  1. Create a nuget config that only references the nuget.org feed:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <packageSources>
    <add key="public" value="https://api.nuget.org/v3/index.json" />
    </packageSources>
    </configuration>
  2. call dotnet tool update --global dotnet-ef --configfile .\nuget.config referencing the clean nuget.config

jepperaskdk commented 1 month ago

If the problem is that the feed is not public, you can install the CredentialProvider to make dotnet commands prompt for login: https://github.com/microsoft/artifacts-credprovider