在遗留 .NET 平台上使用 .NET Core 包

Using .NET Core packages on legacy .NET platforms

我正在使用 VS 中的一个新 "Class Library (Package)" 模板创建一个 NuGet 包。我想知道,有什么方法可以使用 PCL 中 而不是 使用 .NET Core 的包?

例如,我有一个包 Enu,其中包含以下 project.json

{
    "title": "Enu",
    // project details...

    "dependencies": {
        "System.Runtime": "4.0.0"
    },

    "frameworks": {
        "dotnet": { }
    }
}

然后我有一个针对 .NET 4.5、Windows 8 和 Windows 8.1 的遗留 PCL。当我尝试通过 Install-Package Enu 安装软件包时,出现以下错误:

PM> Install-Package Enu
# blah blah blah
Install-Package : Could not install package 'Enu 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.

我该怎么做才能解决这个问题?

注意:奇怪的是,它适用于控制台应用程序。

是的,这是可能的。这是一个很好的参考图表(取自here):

tl;dr 要定位所有内容,请将此添加到您的 project.json:

"frameworks": {
    "dotnet": { }, // .NET 4.6 and DNX
    "net45": { }, // .NET Framework 4.5
    "netcore45": { } // WinRT and Silverlight
}