简体   繁体   English

NuGet 元包是否仅保留给 .net 核心?

[英]Is NuGet metapackage reserved to .net core only?

In the .NET doc, I see a lot of explanations around nuget metapackages, bu all the samples are with .NET Core.在 .NET 文档中,我看到很多关于 nuget 元包的解释,但所有示例都使用 .NET Core。 Is it possible to create metapackage for full .net framework assemblies and consume this with a .net framework app?是否可以为完整的 .net 框架程序集创建元包并使用 .net 框架应用程序使用它?

Will it be possible only with ProjectReference and not with packages.config?只能使用 ProjectReference 而不能使用 packages.config 吗?

Thanks!谢谢!

A metapackage is just a package that doesn't contain any content/libraries of its own and has dependencies to all the other packages that it encompasses.元包只是一个包,它不包含自己的任何内容/库,并且依赖于它包含的所有其他包。 This isn't something specific to NuGet, by the way, many package managers have the same concept and usually call them meta packages too.这不是 NuGet 特有的东西,顺便说一下,许多包管理器都有相同的概念,通常也称它们为元包。

About NuGet specifically, since NuGet has to deal with different target frameworks and asset selection, which many package managers don't have to worry about, it might be necessary to put some fake information in the nupkg to make it work properly.具体来说,关于NuGet,由于NuGet 需要处理不同的目标框架和资产选择,许多包管理人员不必担心,因此可能需要在nupkg 中放入一些虚假信息以使其正常工作。 What I think I've seen before is to create an empty file named _._ in the lib\\target framework folders that match the TFMs that the dependant packages use.我想我之前看到的是在lib\\target framework文件夹中创建一个名为_._的空文件,该文件与依赖包使用的 TFM 相匹配。 For example, if you create a metapackage for packages that have libs for net45 and netstandard2.0, then you'd have two files in the nupkg, lib/net45/_._ and lib/netstandard2.0/_._ , both are empty.例如,如果您为具有 net45 和 netstandard2.0 库的包创建元包,则 nupkg 中有两个文件, lib/net45/_._lib/netstandard2.0/_._ ,两者都是空的。 However, I haven't tested this myself, so you should, but just in case a nupkg with only a nuspec and nothing else doesn't work, try this.但是,我自己还没有测试过,所以你应该这样做,但以防万一只有 nuspec 而没有其他东西的 nupkg 不起作用,试试这个。

Since meta packages aren't otherwise special (they have the same package type as "regular" packages), they work just fine with both packages.config and PackageReference.由于元包在其他方面并不特殊(它们与“常规”包具有相同的包类型),因此它们与 packages.config 和 PackageReference 一起工作得很好。 Meta packages are perhaps most useful for PackageReference, because it supports transitive dependencies.元包可能对 PackageReference 最有用,因为它支持传递依赖。 In other words, the user adds the metapackage, their csproj gets one reference and is otherwise "clean".换句话说,用户添加元包,他们的 csproj 获得一个引用,否则“干净”。 With packages.config, when they add the metapackage, all of the transitive dependencies will also get added to packages.config and csproj.使用packages.config,当他们添加元包时,所有的传递依赖也将被添加到packages.config 和csproj。

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

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