简体   繁体   English

如何从Nuget包中选择目标框架

[英]How to choose target framework from Nuget package

I'm using a NuGet package which contains the assemblies for 2 target frameworks: net45 and netstandard1.5 我正在使用一个NuGet程序包,其中包含2个目标框架的程序集:net45和netstandard1.5

My project is targeting net471 (so compatible with netstandard1.5). 我的项目针对net471(因此与netstandard1.5兼容)。 When I add the package, it copies the dll from net45 folder. 当我添加软件包时,它将从net45文件夹复制dll。 How to force NuGet to use the dll from the standard folder? 如何强制NuGet使用标准文件夹中的dll?

The problem with the net45 version is that it needs an older version of a dependency package, the standard dll has no dependency. net45版本的问题在于它需要较旧版本的依赖程序包,标准dll没有依赖程序。

How to choose target framework from Nuget package 如何从Nuget包中选择目标框架

According to the official document Matching assembly versions and the target framework in a project : 根据官方文档Matching Assembly版本和项目中的目标框架

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. 当NuGet安装具有多个程序集版本的软件包时,它将尝试将程序集的框架名称与项目的目标框架进行匹配。

So, just as Matt said: " NuGet will use the assembly that is the closest match. More specific target framework wins. ", NuGet will install the .net framework assembly to your .net framework project. 因此,正如Matt所说:“ NuGet将使用最接近的程序集。赢得更具体的目标框架。 ”,NuGet会将.net框架程序集安装到您的.net框架项目中。

To resolve this issue, you can use Matt suggestion, directly reference the .NET Standard assembly yourself in the project or you can download that nuget package manually, set it to the local feed , open it with NuGet Package Explorer, delete the folder net45 under the lib folder, install that package from local feed, then nuget will use the dll from the standard folder. 要解决此问题,您可以使用Matt的建议, 直接在项目中自己引用.NET Standard程序集,也可以手动下载该nuget程序包,将其设置为本地供稿 ,使用NuGet程序包资源管理器将其打开,删除下面的文件夹net45 lib文件夹,从本地feed安装该软件包,然后nuget将使用标准文件夹中的dll。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM