在NetStandard1.3项目中引用PCLCrypto

时间:2017-05-10 12:37:14

标签: portable-class-library .net-standard project.json

我正在尝试使用NetStandard 1.3在项目中添加对包PCLCrypto(2.0.147)的引用

在project.json中添加导入“portable-net45 + netcore45 + wpa81”后,它会构建,但会继续显示错误。

project.json:

{
  "supports": {},
  "dependencies": {
    "Microsoft.EntityFrameworkCore": "1.1.1",
    "NETStandard.Library": "1.6.1",
    "PCLCrypto": "2.0.147",
    "System.ComponentModel.Primitives": "4.1.0",
    "WraUtil.Helpers": "1.8.2"
  },
  "frameworks": {
    "netstandard1.3": {
      "imports": "portable-net45+netcore45+wpa81"
    }
  }
}

错误:

Severity    Code    Description Project File    Line    Suppression State
Error       Package PInvoke.NCrypt 0.3.2 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package PInvoke.NCrypt 0.3.2 supports:
  - net40 (.NETFramework,Version=v4.0)
  - portable-net40+win8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile92)
  - portable-net45+win8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile111)
Error       Package Validation 2.2.8 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package Validation 2.2.8 supports:
  - dotnet (.NETPlatform,Version=v5.0)
  - portable-dnxcore50+monoandroid10+monotouch10+net45+win+wp8+wpa81+xamarinios10 (.NETPortable,Version=v0.0,Profile=net45+dnxcore50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10)
  - portable-net40+sl5+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile328)
Error       Package PCLCrypto 2.0.147 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package PCLCrypto 2.0.147 supports:
  - monoandroid23 (MonoAndroid,Version=v2.3)
  - monotouch10 (MonoTouch,Version=v1.0)
  - net45 (.NETFramework,Version=v4.5)
  - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
  - portable-win81+wpa81 (.NETPortable,Version=v0.0,Profile=Profile32)
  - wp8 (WindowsPhone,Version=v8.0)
  - xamarinios10 (Xamarin.iOS,Version=v1.0)
Error       One or more packages are incompatible with .NETStandard,Version=v1.3.
Error       Package PCLCrypto 2.0.147 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package PCLCrypto 2.0.147 supports:
  - monoandroid23 (MonoAndroid,Version=v2.3)
  - monotouch10 (MonoTouch,Version=v1.0)
  - net45 (.NETFramework,Version=v4.5)
  - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
  - portable-win81+wpa81 (.NETPortable,Version=v0.0,Profile=Profile32)
  - wp8 (WindowsPhone,Version=v8.0)
  - xamarinios10 (Xamarin.iOS,Version=v1.0)
Error       One or more packages are incompatible with .NETStandard,Version=v1.3.
Error       Package Validation 2.2.8 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package Validation 2.2.8 supports:
  - dotnet (.NETPlatform,Version=v5.0)
  - portable-dnxcore50+monoandroid10+monotouch10+net45+win+wp8+wpa81+xamarinios10 (.NETPortable,Version=v0.0,Profile=net45+dnxcore50+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10)
  - portable-net40+sl5+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile328)
Error       Package PInvoke.NCrypt 0.3.2 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package PInvoke.NCrypt 0.3.2 supports:
  - net40 (.NETFramework,Version=v4.0)
  - portable-net40+win8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile92)
  - portable-net45+win8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile111)

我还需要配置其他内容吗?

1 个答案:

答案 0 :(得分:2)

imports文件的project.json字段中,您应该放置一个与PCLCrypto 2.0.147兼容的目标框架,这些错误基本上告诉您有哪些选项。

例如,其中一个受支持的目标框架是portable-net45+win8+wp8+wpa81,它与netstandard1.0兼容,这意味着它也可以被netstandard1.3项目引用(您可以找到{{} 3}}有关旧PCL配置文件与新.NET标准版本之间兼容性的更多信息。)

因此,请将您的imports字段更新为:"imports": "portable-net45+win8+wp8+wpa81"

小额奖金 - 如果您决定从project.json转移到新的MSBuild(csproj)风格项目,您可以实现相同的目标:

<PropertyGroup>
    <TargetFramework>netstandard1.3</TargetFramework>
    <PackageTargetFallback>portable-net45+win8+wp8+wpa81</PackageTargetFallback>
</PropertyGroup>