【问题标题】:Reference a .NET Standard 1.6 library from a .net library从 .net 库中引用 .NET Standard 1.6 库
【发布时间】:2018-01-28 15:12:56
【问题描述】:

我正在尝试在我的应用程序中使用库,我对此有点陌生,我正在遵循此说明, https://docs.microsoft.com/en-us/dotnet/core/tutorials/consuming-library-with-visual-studio?tabs=csharp

基本上我已经打开了库解决方案并向其中添加了一个新项目, 但是,当我运行时,出现以下错误:

项目“..\src\gdax.netcore.csproj”以“netstandard1.6”为目标。它不能被以 '.NETFramework,Version=v4.5' 为目标的项目引用。 GdApp1

我不确定如何解决这个问题,我尝试在库和项目中更改各种目标版本,如果我将项目目标设置为 4.6.1,我会丢失与我正在使用的图书馆。

我正在尝试使用这个库https://github.com/sefbkn/gdax.netcore 在这一点上,我的代码基本上是他们示例的直接副本

缺少的参考资料和错误是:

The type or namespace name 'RequestAuthenticator' could not be found (are you missing a using directive or an assembly reference?)  

The type or namespace name 'ProductClient' could not be found (are you missing a using directive or an assembly reference?) 

The type or namespace name 'gdax' could not be found (are you missing a using directive or an assembly reference?)  

The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.    

【问题讨论】:

  • 对,我确实看过,所以 .netstandard 1.6 应该与 4.6.1 框架兼容吧?当我更改为那个时,我怎么会丢失参考?
  • 您能否更详细地解释缺少的参考资料?您要使用什么库以及使用什么代码来调用它?发布代码将帮助我们帮助您。
  • 非常感谢您的帮助 Lesscode,我已经更新了主帖
  • 你是如何引用这个库的?我没有看到它的 Nuget 包,所以您只是将项目代码添加到您的解决方案中吗?确保您的源代码中有正确的 using Boukenken.Gdax; 声明。

标签: c# .net .net-standard


【解决方案1】:

这里有多个步骤

  1. 检查您使用的是最新版本的 VS(建议 15.5.* 以支持 .NET 4.7.1+netstandard)
  2. 至少以 .NET 4.6.1 为目标以引用 netstandard1.6 库
  3. 关注https://github.com/dotnet/announcements/issues/31 解决库加载问题。这涉及为使用它的应用程序启用自动绑定重定向生成,并修改 csproj 以进行单元测试。

或者,等待 .NET 4.7.2 和 Visual Studio 2017 版本 15.6 不再需要手动步骤。

【讨论】:

    【解决方案2】:

    您还需要将 NETStandard.Library nuget 包添加到尝试使用任何 .Net Standard dll 的项目中。

    https://www.nuget.org/packages/NETStandard.Library/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-06
      • 2017-07-04
      • 2021-12-04
      • 2017-05-12
      • 1970-01-01
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      相关资源
      最近更新 更多