在旧版.NET平台上使用.NET Core软件包 [英] Using .NET Core packages on legacy .NET platforms

查看:132
本文介绍了在旧版.NET平台上使用.NET Core软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS中的那些新类库(包)"模板之一创建NuGet包.我想知道,有什么方法可以从不使用.NET Core的PCL中使用我的软件包?

I'm creating a NuGet package using one of those new "Class Library (Package)" templates in VS. I want to know, is there any way I can use my package from a PCL that does not use .NET Core?

例如,我有一个带有以下project.json的软件包Enu:

For example, I have a package, Enu, with the following 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安装软件包时,出现以下错误:

Then I have a legacy PCL that targets .NET 4.5, Windows 8, and Windows 8.1. When I try to install the package via Install-Package Enu, I get the following error:

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.

该如何解决?

注意:很奇怪,它可以在控制台应用程序上运行.

note: Weirdly enough, it works on a console application.

推荐答案

是的,有可能.这是一个很好的参考图(摘自此处):

Yep, it's possible. Here's a nice graph for reference (taken from here):

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

tl;dr To target everything add this to your project.json:

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

这篇关于在旧版.NET平台上使用.NET Core软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆