.Net NuGet 包多目标 .NetStandard 2.0 预发布/.NetFramework v4.6.1 兼容 UWP 项目

.Net NuGet package multi target .NetStandard 2.0 pre-release/.NetFramework v4.6.1 compatible to UWP project

我创建了一个支持 .NetStandard 2.0 预发布版和 .NetFramework v4.6.1 之间的多目标的 NuGet 包(在 Visual Studio 15.3 预览版中构建和使用)

我知道 .NetStandard 2.0 预发布版在 vnext 之前与 UWP 不兼容,但据我所知,.NetFramework v4.6.1 是兼容的。

我目前无法将我的 NuGet 包安装到 UWP 项目,有没有办法让它兼容?

.NET Standard 是 .NET API 的正式规范,旨在用于所有 .NET 运行时。它为所有要实施的 .NET 平台定义了一组统一的 API,与工作负载无关。

当一个 NuGet 包以 .NET Standard 2.0 为目标时,这意味着这个包可以在 .NET Core 2.0.NET Framework 4.6.1(带有工具 2.0 预览版).所以从字面上看,.Net Standard 2.0.NET Framework 4.6 之间没有多目标。 1,应该是.NET Core 2.0和[=30=之间的multi-target之类的东西].NET Framework 4.6.1.

如果您希望您的包与 UWP.NET Framework 4.6.1 兼容,那么您可以针对 .NET 标准 1.4。这是目前两个平台都支持的.NET Standard 的最高版本。因此无法将 .NET Standard 2.0 包安装到 UWP 项目。

When choosing a .NET Standard version, you should consider this trade-off:

  • The higher the version, the more APIs are available to you.
  • The lower the version, the more platforms implement it.

In general, we recommend you to target the lowest version of .NET Standard possible. So, after you find the highest .NET Standard version you can target, follow these steps:

  1. Target the next lower version of .NET Standard and build your project.
  2. If your project builds successfully, repeat step 1. Otherwise, retarget to the next higher version and that's the version you should use.

更多信息,请参阅.NET platforms support

而对于 UWP.NET Framework 4.6.1,它们之间没有兼容性。尽管 .NET Framework 中提供的类型的子集可用于使用 C# 或 Visual Basic 创建 UWP 应用程序,但这是因为这些 API 是 .NET Standard 的一部分,因此它们在 UWP 中可用。如果包的目标是 .NET Framework 4.6.1,那么它也不能在 UWP 中使用。