从.net库引用.NET Standard 1.6库

时间:2018-01-27 14:00:40

标签: c# .net .net-standard

我正在尝试在我的应用程序中使用库,我对此有点新意我遵循这些说明, 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'.    

2 个答案:

答案 0 :(得分:1)

这里有多个步骤

  1. 检查您使用的是最新版本的VS(建议使用15.5。* for .NET 4.7.1 + netstandard支持)
  2. 至少定位.NET 4.6.1以引用netstandard1.6库
  3. 关注https://github.com/dotnet/announcements/issues/31以解决库加载问题。这包括为使用它的应用程序启用自动绑定重定向生成,以及修改单元测试的csproj。
  4. 或者,等待.NET 4.7.2和Visual Studio 2017版本15.6不再需要手动步骤。

答案 1 :(得分:-1)

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

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