juanitooo
juanitooo

Reputation: 551

Unable to install packages using dotnet add package

I'm a .NET newbie using VS Code while following an online course on Angular and .NET Core. The course requires the AutoMapper.Extensions.Microsoft.DependencyInjection package to be installed but I keep getting the following errors when I try install any package.

I use the following command to install the package:

dotnet add package AutoMapper.Extensions.Microsoft.DependencyInjection

What I've tried so far:

  1. Added PackageReference manually into the .csproj file then using dotnet restore - results in the same error (NU1100)
  2. Cleared the NuGet package cache using dotnet nuget locals all --clear - results in the same error

It was working before when I tried to install the Microsoft.EntityFrameworkCore.Sqlite package at the beginning of the course and now for some reason I can't install any package.

Do note that I'm not able to use the NuGet extension as it's not working behind a corporate proxy.

Any help would be greatly appreciated :)

Upvotes: 13

Views: 16522

Answers (2)

nightblade9
nightblade9

Reputation: 415

Turns out this can also happen in cases when your package doesn't support your solution.

In my case, I had a .NET 8 project:

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

I was trying to install Microsoft.AspNetCore.Authentication.JwtBearer version 9.0.1, which is only compatible with net9.0.

The solution? Install the 8.0.12 version of the package instead. Problem solved.

Upvotes: 0

juanitooo
juanitooo

Reputation: 551

I finally fixed the issue by deleting the NuGet.Config file in C:\Users\<user>\AppData\Roaming\NuGet folder then running dotnet restore

Running dotnet restore created a fresh config file on the folder which i noticed has a different packageSources value than the old one.

The old one had https://www.nuget.org/api/v2/ while the new one had https://api.nuget.org/v3/index.json

I completely forgot that I have VS 2010 (with nuget) installed which was responsible for the old config file and I did not realize that nuget from the dotnet-cli was also using the same old configurations.

Upvotes: 42

Related Questions