简体   繁体   English

使用 NuGet 包管理器控制台时无法访问源

[英]Source unreachable when using the NuGet Package Manager Console

We are moving our package management from manually updating files to NuGet.我们正在将包管理从手动更新文件转移到 NuGet。 I am trying to install older versions of packages to match the one we already have in source control.我正在尝试安装旧版本的软件包以匹配我们在源代码管理中已有的软件包。 There is no way to do this from the UI so I use the command line to get the proper version.无法从 UI 执行此操作,因此我使用命令行来获取正确的版本。

For some reason, Install-Package keeps on telling me that the nuget gallery is unreachable.出于某种原因, Install-Package一直告诉我 nuget 库无法访问。

The source at nuget.org [ https://www.nuget.org/api/v2/] is unreachable. nuget.org [ https://www.nuget.org/api/v2/] 上的源无法访问。 Falling back to NuGet Local Cache回退到 NuGet 本地缓存

This happens only in one of our solutions.这仅发生在我们的一种解决方案中。 If I create a new solution or use another one in the same repository, packages will install as expected.如果我在同一个存储库中创建一个新解决方案或使用另一个解决方案,软件包将按预期安装。 I can even install the packages in a dummy solution to fill the local cache and then install them successfully in the faulty solution.我什至可以在虚拟解决方案中安装软件包以填充本地缓存,然后在错误解决方案中成功安装它们。 I have tried to Invoke-WebRequest on the url from the NuGet Console and I get an HTTP 200.我试图从 NuGet 控制台的 url 上Invoke-WebRequest ,但我得到了一个 HTTP 200。

What can cause this?什么会导致这种情况? Is there a way to override the package sources on a per solution/project basis?有没有办法在每个解决方案/项目的基础上覆盖包源?

Even though my Package Source was set to nuget.org in Package Manager Console, explicitly adding the -Source nuget.org argument fixed this for me.即使我的包源在包管理器控制台中设置为 nuget.org,显式添加-Source nuget.org参数也为我解决了这个问题。

So an example of use would be:因此,一个使用示例是:

Install-Package Akka.net -Source nuget.org

Akka.net being your package that you want to install, its just an example here. Akka.net 是您要安装的软件包,这里只是一个示例。

I had to copy the default NuGet source in Visual Studio's options.我不得不在 Visual Studio 的选项中复制默认的 NuGet 源。 With the copied source, I changed the URL from https to http .使用复制的源代码,我将 URL 从https更改为http This resolved the problem for me.这为我解决了问题。

Credit for this suggestion belongs here: https://nuget.codeplex.com/discussions/561075#PostDetailsCell_1354351 , to "jpharris4".此建议的功劳属于此处: https ://nuget.codeplex.com/discussions/561075#PostDetailsCell_1354351,“jpharris4”。

You can change NuGet source from UI as well.您也可以从 UI 更改 NuGet 源。 Just change NuGet source to older version and it should work fine.只需将 NuGet 源代码更改为旧版本,它应该可以正常工作。

在此处输入图片说明

There seems to be still few bugs in VS 2015 related to api.nuget.org (v3). VS 2015 中与 api.nuget.org (v3) 相关的错误似乎仍然很少。

I'm not sure what can cause your issue, but there is indeed a way to override package sources on a per-solution basis, but only if you've enabled NuGet Package Restore on the given solution.我不确定什么会导致您的问题,但确实有一种方法可以在每个解决方案的基础上覆盖包源,但前提是您在给定的解决方案上启用了 NuGet 包还原

Once a solution has enabled NuGet Package Restore a folder called ".nuget" gets added to the solution.解决方案启用 NuGet 包还原后,一个名为“.nuget”的文件夹将添加到解决方案中。 Under this will be a file called "NuGet.targets" that has an ItemGroup whose Condition is " '$(PackageSources)' == '' " like the one you'll see in the attached image.在这下面将是一个名为“NuGet.targets”的文件,它有一个条件为“'$(PackageSources)' == ''”的项目组,就像您将在附加图像中看到的那样。

If the ItemGroup is empty (or completely commented out, as in the illustration) then the solution will use a specific file that should be the same as the sources listed under TOOLS >> OPTIONS.如果 ItemGroup 为空(或完全注释掉,如图所示),则解决方案将使用一个特定文件,该文件应该与 TOOLS >> OPTIONS 下列出的源相同。 But if you uncomment or add PackageSource items to that ItemGroup the solution will search the package sources listed and ONLY the ones listed.但是,如果您取消注释或将 PackageSource 项目添加到该 ItemGroup,解决方案将搜索列出的包源,并且仅搜索列出的包源。

Nuget.targets 文件的内容

In my Package Manager Console i could not see any sources在我的包管理器控制台中,我看不到任何来源

Going to: Tools -> Options -> Nuget Package Manager -> Package Sources转到:工具 -> 选项 -> Nuget 包管理器 -> 包源

I found the sources.我找到了来源。 Unchecking them, and them checking them back made the re-appear in my Package Manager Console取消选中它们,然后他们重新检查它们使我的包管理器控制台中重新出现

我必须提供命令以及完整的 url 作为Install-Package MySql.Data.Entity -Version 6.9.8 -Source http://www.nuget.org/api/v2

In my case the cause was that the package had an agreement.在我的情况下,原因是包裹有协议。 Through the UI - "Manage NuGet Packages" dialog you have the option to accept and continue.通过 UI -“管理 NuGet 包”对话框,您可以选择接受并继续。

The Package Manager Console in VS 2013 seems to have an issue with this. VS 2013 中的包管理器控制台似乎对此有问题。 As others have said restarting VS 2013 might resolve it for the console.正如其他人所说,重新启动 VS 2013 可能会为控制台解决它。

This is worked for me in VS 2015 prof: Tools -> Options -> Nuget Package Manager -> Package Sources这在 VS 2015 教授中对我有用工具 -> 选项 -> Nuget 包管理器 -> 包源

  1. Press Add button按添加按钮
  2. Edit in Name label: nuget.org在名称标签中编辑:nuget.org
  3. Edit in Source label: https://www.nuget.org/api/v2/在源标签中编辑: https : //www.nuget.org/api/v2/
  4. Press OK按确定

Hope it helps ;)希望能帮助到你 ;)

I had the same issue with the same message.我对相同的消息有同样的问题。 But the reason of my problem was lost connection to TFS.但我的问题的原因是失去了与 TFS 的连接。 My TFS server was hosted in other network and I used VPN for access to it.我的 TFS 服务器托管在其他网络中,我使用 VPN 访问它。 When I tried to install the package without established connection to TFS (VPN was turned off) I got the same problem.当我尝试在没有与 TFS 建立连接的情况下安装软件包(VPN 已关闭)时,我遇到了同样的问题。

Be aware of this TFS behavior.请注意此 TFS 行为。

Happens because you work offline mode, when you reconnect the network will need to log off and log back.发生这种情况是因为您在离线模式下工作,当您重新连接网络时将需要注销并重新登录。 Package manager will smoothly re-initialize.包管理器将顺利地重新初始化。

I have faced this issue VS2013 and wasted 3 hours of time.我在 VS2013 遇到过这个问题,浪费了 3 个小时的时间。

Not Sure what was the cause of the issue.不确定问题的原因是什么。 But none of the above solutions worked for me.但上述解决方案都不适合我。

Re-Installtion of Nuget Package Manager console worked for me.重新安装 Nuget 包管理器控制台对我有用。

Tools - > Extensions and Updates -> Under All Look for Nuget Package Manager for Visual Studio and hit uninstall.工具 -> 扩展和更新 -> 在所有下查找 Visual Studio 的 Nuget 包管理器并点击卸载。

Go to https://marketplace.visualstudio.com/items?itemName=NuGetTeam.NuGetPackageManagerforVisualStudio2013 and download the extension.转到https://marketplace.visualstudio.com/items?itemName=NuGetTeam.NuGetPackageManagerforVisualStudio2013并下载扩展。

在此处输入图片描述可能是您的办公室/家庭防火墙阻止了 nuget.org,因此请尝试连接不同的互联网网络,例如从您的手机或 wifi 连接。我能够通过这种方法解决。

None of these solutions worked for me with VS2013.这些解决方案都不适用于 VS2013。 Yes I know it's the year 2020. In the end I downloaded the nuget package to a local folder, added the folder to the nuget settings, and then voila!, was able to install the package.是的,我知道现在是 2020 年。最后我将 nuget 包下载到本地文件夹,将该文件夹添加到 nuget 设置中,然后瞧!能够安装该包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM