Search code examples
visual-studionuget

Package Manager not showing packages under browse - An error occurred while retrieving package metadata


When creating a simple project for c# consol application, and clicking on Manage Nuget packages, is shows "loading ..." and quickly shows: Error occurred and no packages are showing.
Setup:
OS: Windows 11
VS: Recently new install of 2022 community v 17.4.5
PM: Only one source - Name:Nuget Source: https://www.nuget.org
Steps:
Create new project type: C# Console app, Project file:

 

    <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

enter image description here

The moment I right-click on Package Manager and open it I get the following message

An error occurred while retrieving package metadata for 'microsoft.entityframeworkcore.sqlserver' from source 'Nuget'.

I tried, getting out and in from VS and rebooting the computer but nothing helped.
What can be the issue? and why the PM is trying to look for 'microsoft.entityframeworkcore.sqlserver'
Thanks


Solution

  • I notice you mentioned you were using https://www.nuget.org/ as nuget source.

    This is not correct.

    The below are some concepts you need to know.

    1, Nuget Tool

    Nuget is a free and open-source package manager for the Microsoft development platform. Nuget source is a concept under this tool.

    2, Nuget Gallery

    This is a website, you can search the packages maded by official of personal.


    Both URLs you mentioned are associated with NuGet concept, but they are still different:

    https://www.nuget.org/:

    This is the main website for the NuGet project. Here, you can search for packages, publish new packages, and read documentation on how to use NuGet, among other things. You can also download the NuGet client tools from this website.

    https://api.nuget.org/v3/index.json:

    This URL is the entry point for the NuGet V3 API. It's not intended to be used with a web browser. Instead, it's designed for use by the NuGet client tools (like nuget.exe or the NuGet features in Visual Studio) when they need to interact with a NuGet repository. This URL provides a JSON response that includes the URLs of other services in the NuGet V3 API, like search, package metadata, and package download services.

    So, www.nuget.org is a user-facing website, while api.nuget.org/v3/index.json is a service-facing API endpoint.

    You can also refer to this official document:

    sources command (NuGet CLI)

    You can see that it mentioned:

    Note that the source URL for nuget.org is https://api.nuget.org/v3/index.json.