尝试在 .Net 中安装包时出错

Error caused when trying to Installing package in .Net

当我尝试使用以下命令在 Visual Studio 2017 年安装软件包时,

PM> Install-Package Microsoft.IdentityModel -Version 7.0.0

我收到以下错误

Attempting to gather dependency information for package 'Microsoft.IdentityModel.7.0.0' with respect to project 'Portal.System', targeting '.NETFramework,Version=v4.0'

Install-Package : An error occurred while retrieving package metadata for 'Microsoft.IdentityModel.7.0.0' from source 'nuget.org'.

error occurred while sending the request.
The remote name could not be resolved: 'api.nuget.org' At line:1 char:1

  • Install-Package Microsoft.IdentityModel -Version 7.0.0
  •  + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
     + FullyQualifiedErrorId : NuGetCmdletUnhandledException, NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
    

我该如何解决这个问题。

https://www.nuget.org 下载最新的 nuget 命令行工具 然后 运行 下面的命令

nuget.exe locals -clear all

重新启动您的 visual studio。 这个问题会发生在任何全新安装 Windows/VS/tooling 的系统上,很可能是安装程序的错误。

同意 zivkan,此问题可能与您使用 VS2017 时的互联网连接有关。

特别是你需要检查你的IE浏览器是否可以访问nuget.org网站。我认为这个问题表明您的 DNS provider 有问题。请检查这一点并修复连接。

此外:如果您在代理后面使用 nuget.org,有关 nuget.config 的一些详细信息可能会有所帮助。