uap10.0 netstandard2.0 nuget 消歧

uap10.0 netstandard2.0 disambiguation in nuget

我正在创建一个 Nuget 包,其中包含我的 DLL 的 uap10.0 和 netstandard2.0 版本。

uap10.0 实际上与 .netstandard1.3 兼容,可用于 Windows 上 Windows 上的通用 Windows 应用程序 Windows 10 Fall Creators Update。从Windows10 Fall Creators Update开始,可以使用netstandard2.0

我想知道 Nuget 如何选择要使用的版本。例如,如果我创建一个 UWP 项目并且 select 目标和最小版本为 Windows 10 Fall Creators 然后使用 Install-package MyPackage,它会选择 netstandard2.0 还是 uap10.0 版本动态链接库?或者我(包供应商)应该如何控制它?

For instance, if I create a UWP project and select Target and Min version as Windows 10 Fall Creators and then use Install-package MyPackage, will it pick netstandard2.0 or uap10.0 version of the DLL?

在我看来,UWP项目肯定会选择uap10.0版本。

我已经为此做了一些测试来检查结果,在 UWP 项目中,如果我们使用包含两个 uap10.0 and netstandard2.0 版本的包,它将始终选择 uap10.0 而不是 .netstandard2.0版本。只有当我尝试使用仅包含 netstandard2.0 版本的包时,UWP 才会选择 netstandard2.0 版本。

When NuGet installs a package that has multiple assembly versions, it tries to match the framework name of the assembly with the target framework of the project.

请检查this official document,这样NuGet将使用最匹配的程序集。(程序集的框架名称<=>项目的目标框架名称)

所以更具体目标框架获胜。至于您的情况,在以 uap 为目标的 UWP 项目中,它将从包含多个版本的包中选择 uap10.0 版本。而这个你不需要去控制,你只需要在打包之前将不同版本的程序集放在corresponding framework folder下即可。

更新:

Alex 提醒的想法。创建 nuget 包时使用这样的结构:

-lib
  -uap10.0
     --Test.dll
  -uap10.0.16299
     --Test.dll(actually target .net standard2.0)

当最低版本为16299及更新的UWP项目时,它将选择位于uap10.0.16299文件夹中的.net标准版本。而对于那些 min 低于 16299 的旧的,它会从 uap10.0 文件夹中选择程序集。