无法使用 dotnet add package 安装包 [英] Unable to install packages using dotnet add package

查看:100
本文介绍了无法使用 dotnet add package 安装包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 .NET 新手,正在学习 Angular 和 .NET Core 的在线课程,同时使用 VS Code.该课程需要安装 AutoMapper.Extensions.Microsoft.DependencyInjection 包,但是当我尝试安装 any 包时,我不断收到以下错误.

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.

  • 无法解析 <package_name>对于.NETCoreApp,Version=v2.2"

与项目

我使用以下命令安装包:

I use the following command to install the package:

dotnet add package AutoMapper.Extensions.Microsoft.DependencyInjection

到目前为止我尝试过的:

  1. PackageReference 手动添加到 .csproj 文件中,然后使用 dotnet restore - 导致相同的错误 (NU1100)
  2. 使用 dotnet nuget locals all --clear 清除 NuGet 包缓存 - 导致相同的错误
  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

当我在课程开始时尝试安装 Microsoft.EntityFrameworkCore.Sqlite 包时,它可以正常工作,现在由于某种原因我无法安装任何包.

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.

请注意,我无法使用 NuGet 扩展,因为它不在公司代理后面工作.

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 :)

推荐答案

我终于通过删除 C:Users 中的 NuGet.Config 文件解决了这个问题AppDataRoamingNuGet 文件夹,然后运行 ​​dotnet restore

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

运行 dotnet restore 在文件夹上创建了一个新的配置文件,我注意到它与旧的 packageSources 值不同.

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

旧的有https://www.nuget.org/api/v2/ 而新的有 https://api.nuget.org/v3/index.json

我完全忘记了我安装了 VS 2010(带有 nuget),它负责旧的配置文件,我没有意识到来自 dotnet-cli 的 nuget 也在使用相同的旧配置.

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.

这篇关于无法使用 dotnet add package 安装包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆