【问题标题】:ASP.NET 5: Error with Nuget package in Class library PackageASP.NET 5:类库包中的 Nuget 包出错
【发布时间】:2016-01-15 19:45:57
【问题描述】:

我开始玩 VS2015 社区版和 ASP.NET 5。

我已将新类库(包)作为新项目添加到我的解决方案中,但无法在其中安装 NuGet 包。还原后,我有一个“参考(错误 - 请参阅错误列表)”。

如果我将一个基本库类 (.dll) 作为新项目添加到我的解决方案中并尝试安装相同的 NuGet 包,它会像以前一样完美运行。

也许,我误解了这个新的类库包是如何工作的,我试图滥用它......

感谢您的帮助。

----------------------------------- ---------------编辑 1--------------------------------- -------------------------- Project.json:这种情况下的警告标志位于 EF 包上:

{
    "version": "1.0.0-*",
    "description": "testFinal Class Library",
    "authors": [ "SylvainC" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "System.Collections": "4.0.10-beta-23019",
        "System.Linq": "4.0.0-beta-23019",
        "System.Threading": "4.0.10-beta-23019",
        "System.Runtime": "4.0.10-beta-23019",
        "Microsoft.CSharp": "4.0.0-beta-23019",
        "EntityFramework": "6.1.3"
    },

    "frameworks": {
        "dotnet": { }
    }
}

----------------------------------- -----更新到 beta8 后编辑 1 bis----------------------------

{
  "version": "1.0.0-*",
  "description": "ClassLibrary5 Class Library",
  "authors": [ "SylvainC" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
    "dnx451": { }
  },
  "dependencies": {
    "EntityFramework": "6.1.3"
  }
}

----------------------------------- ---------------编辑 2-------------------------------- --------------------------

升级 dnvm(dvnm 升级)后,我能够运行“dnu restore”命令但收到以下错误:

>dnu restore
Microsoft .NET Development Utility Clr-x86-1.0.0-beta8-15858

  GET https://www.nuget.org/api/v2/
  GET https://www.myget.org/F/aspnetmaster/api/v2/
Restoring packages for D:\testFinal\project.json
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection'
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='System.Reflection'
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Globalization'
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='System.Globalization'
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='EntityFramework'
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='EntityFramework'
Warning: FindPackagesById: System.Globalization
  An error occurred while sending the request.
Warning: FindPackagesById: System.Globalization
  An error occurred while sending the request.
Warning: FindPackagesById: System.Reflection
  An error occurred while sending the request.
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='System.Globalization'
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='System.Reflection'
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Globalization'
Warning: FindPackagesById: System.Reflection
  An error occurred while sending the request.
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection'
Warning: FindPackagesById: EntityFramework
  An error occurred while sending the request.
Warning: FindPackagesById: EntityFramework
  An error occurred while sending the request.
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='EntityFramework'
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='EntityFramework'
Warning: FindPackagesById: System.Reflection
  An error occurred while sending the request.
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='System.Reflection'
Warning: FindPackagesById: System.Globalization
  An error occurred while sending the request.
Warning: FindPackagesById: System.Globalization
  An error occurred while sending the request.
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Globalization'
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='System.Globalization'
Warning: FindPackagesById: System.Reflection
  An error occurred while sending the request.
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection'
Warning: FindPackagesById: EntityFramework
  An error occurred while sending the request.
  GET https://www.nuget.org/api/v2/FindPackagesById()?id='EntityFramework'
Warning: FindPackagesById: EntityFramework
  An error occurred while sending the request.
  GET https://www.myget.org/F/aspnetmaster/api/v2/FindPackagesById()?id='EntityFramework'
Error: FindPackagesById: System.Reflection
  An error occurred while sending the request.
----------
Error: FindPackagesById: System.Globalization
  An error occurred while sending the request.
Error: FindPackagesById: System.Globalization
  An error occurred while sending the request.
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:8888
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---

---------------------------------------------- 编辑 3带有最终错误和提要------------------

Restore failed
An error occurred while sending the request.
NuGet Config files used:
    C:\Users\sylvainc\AppData\Roaming\NuGet\nuget.config
Feeds used:
    https://www.nuget.org/api/v2/
    https://www.myget.org/F/aspnetmaster/api/v2/

西尔万

【问题讨论】:

  • 可以分享一下project.json文件吗?
  • 右键单击引用并选择恢复包。输出窗口中显示了什么?
  • 我遇到了同样的问题,并通过从命令行运行 dnu restore 解决了它。
  • 谢谢@andrej。我已经运行了 dnu restore 但仍然出现错误。我已经相应地编辑了我的帖子
  • 感谢@VictorHurdugaci,我已经编辑了我的帖子并添加了project.json

标签: asp.net-core asp.net-core-mvc


【解决方案1】:

这似乎是一个代理问题给我这个No connection could be made because the target machine actively refused it 127.0.0.1:8888 错误。

用 Fiddler 跟踪它,我发现打开 Fiddler 后,恢复过程和添加新的 Nuget 包运行良好。情况与这篇帖子Why calling API in ASP.NET works only if I have Fiddler open? 或此处:http://www.telerik.com/blogs/help!-running-fiddler-fixes-my-app- 非常相似。

我还尝试按照http://github.com/aspnet/dnx/issues/451 中的建议在C:\Users\sylvainc\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta8\bin 中创建一个dnx.exe.config。 不幸的是,它似乎不适用于 beta8 版本。

我的第一个解决方法是使用 HTTP 协议访问我的 NuGet 包,如下所示:Visual Studio 2015 - Can't sign in, Use NuGet, etc. behind corporate proxy

我的最终解决方案是在C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config 中使用 Notepad+ 以管理员身份编辑 machine.config 文件,以使用 fiddler 默认代理定义并使用系统代理:

<!--<system.net>
         <defaultProxy enabled="true" useDefaultCredentials="true">
         <proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false"/>
         </defaultProxy>
     </system.net>-->
<system.net>
    <defaultProxy useDefaultCredentials="true" enabled="true">
    <proxy usesystemdefault="True"/>
    </defaultProxy>
</system.net>

现在 ASP.Net 5 工作正常,我什至让我的智能感知现在正常工作,而之前的其他代理定义并非如此......

谢谢

西尔万

【讨论】:

  • Fiddler 也是我的原因。
【解决方案2】:

确保您为Visual studio 安装了最新的工具。您的 project.json 似乎是错误的。

在 Visual Studio 中检查您的 nuget 提要是否存在无效提要并删除这些来源。

检查您的活跃 dnx (*)

dnvm list
Active Version     Runtime Architecture OperatingSystem Alias

   1.0.0-beta4     clr     x86          win
   1.0.0-beta7     clr     x64          win
   1.0.0-beta7     clr     x86          win             b7
   1.0.0-beta7     coreclr x64          win
   1.0.0-beta7     coreclr x86          win
   1.0.0-beta8     clr     x64          win
*  1.0.0-beta8     clr     x86          win             aa, b8
   1.0.0-beta8     coreclr x64          win
   1.0.0-beta8     coreclr x86          win
   1.0.0-rc1-15838 clr     x86          win             rc1a
   1.0.0-rc1-16031 clr     x86          win             default
   1.0.0-rc1-16031 coreclr x86          win

tools-&gt;nuget package manager-package manager for solution * 选择一个包源并测试一个包源是否给出任何错误 * 找出你的包在哪个 nuget feed 中可用

在 dnu 输出的末尾有一个使用配置和提要的列表

NuGet Config files used:
    C:\Users\Thom\AppData\Roaming\NuGet\nuget.config
Feeds used:
 https://api.nuget.org/v3-flatcontainer/
 https://www.myget.org/F/aspnetrelease/api/v3/flatcontainer/

使用dnu restore -? 查找问题的根源。

试试这个 dnu restore --no-cache --packages .\packages1

试试这样的 package.json

 {
  "version": "1.0.0-*",
  "description": "ClassLibrary3 Class Library",
  "authors": [ "Thom" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "dependencies": {

    "EntityFramework": "6.1.3"
  },
   "frameworks": {
      "dnx451": { },
  }
 }

【讨论】:

  • 感谢@thom-kiesewetter 在工具页面上指出我。我按照您的说明进行操作,我默认使用 beta8 x86,尝试了 dnu restore (dnu restore --no-cache --packages .\EntityFramework) 但仍然出现此错误:GET nuget.org/api/v2/FindPackagesById()?id='EntityFramework' Error: FindPackagesById: EntityFramework An error occurred在发送请求时。我还用我的新 beta8 project.json 和提要编辑了我的帖子。这可能是这些讨论中定义的代理问题:github.com/aspnet/dnx/issues/451
【解决方案3】:

在我的例子中,包源指向http://packagesource。将其更改为https://www.nuget.org/api/v2/ 修复了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 2016-03-26
    相关资源
    最近更新 更多