为什么我的PCL无法使用System.Runtime?

时间:2015-09-27 02:27:07

标签: c# .net nuget portable-class-library .net-core

我有一个针对以下平台的PCL:

  • .NET Framework 4.5
  • Windows 8
  • Windows Phone 8.1

我需要添加对System.Runtime的引用,因为我想使用另一个依赖它的包。从我所看到的情况来看,version 4.0.0似乎包含了上面提到的目标平台。但是,当我尝试通过NuGet安装它时,我得到了这个堆栈跟踪:

PM> Install-Package System.Runtime -Version 4.0.0
# ...
Install failed. Rolling back...
Package 'System.Runtime 4.0.0' does not exist in project 'PclDummy'
Package 'System.Runtime 4.0.0' does not exist in folder 'C:\Users\James\Documents\Visual Studio 2015\Projects\PclDummy\packages'
Install-Package : Could not install package 'System.Runtime 4.0.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not 
contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

如果System.Runtime支持我的PCL所有平台,为什么会发生这种情况?

2 个答案:

答案 0 :(得分:1)

  

目标' .NETPortable,Version = v4.5,Profile = Profile111'

请务必区分引用程序集和运行时程序集。要编译PCL项目,只需要参考程序集。并且您已经拥有一个System.Runtime,它位于您计算机上的C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.5 \ Profile \ Profile111目录中。它已在您的项目中引用,因此包被正确拒绝。

这种疯狂"但是每个人都已经拥有了这个" Nuget包来自CoreCLR项目。它正在迅速发展,测试版本的发布速度非常快。这是Profile111支持的目标之一,它支持ASP.NET Core 5.0目标。不是你在问题中列出的那个,所以你根本不需要它。但是,如果你愿意那么那个下载这个Nuget包的项目。这完全是自动的,你不要明确要求包裹。

停止尝试安装它。

答案 1 :(得分:0)

似乎版本4.5中不完全支持System.Runtime。

您可以在以下路径中的个人资料文件夹中查看它:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile111

有一个受支持的程序集和命名空间列表。