Why can't my PCL use System.Runtime?

倾然丶 夕夏残阳落幕 提交于 2020-02-02 16:31:43

问题


I have a PCL that targets the following platforms:

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

I need to add a reference to System.Runtime because I want to use another package that depends on it. From what I can see, version 4.0.0 appears to include the target platforms mentioned above. However, when I try installing it via NuGet, I get this stack trace:

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.

Why does this happen if System.Runtime supports all of the platforms my PCL does?


回答1:


that targets '.NETPortable,Version=v4.5,Profile=Profile111'

Be sure to distinguish between reference assemblies and runtime assemblies. To get your PCL project compiled, you only need reference assemblies. And you already have one for System.Runtime, it is located in the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile111 directory on your machine. It is already referenced in your project so the package was correctly rejected.

These kind of crazy "but everybody already has this" Nuget packages come from the CoreCLR project. It is evolving rapidly right now with beta versions released at a very high rate. Which is one of the targets supported by Profile111, it supports an ASP.NET Core 5.0 target. Not one you listed in your question so you probably don't need it at all. But if you would then it would be that project that downloads this Nuget package. Which is entirely automatic, you don't ask for the packages explicitly.

Just stop trying to get it installed.




回答2:


it seems that System.Runtime is not completely supported in version 4.5.

you can check it in the profile folder in following path:

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

there is a list of supported assemblies and namespaces.



来源:https://stackoverflow.com/questions/32803961/why-cant-my-pcl-use-system-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!