SoFunction
Updated on 2025-03-07

Core simplifies assembly references through metapackages

Provided under core by default, some libraries that cannot be used directly in .net core, such aslogDependency injectionOptionsUniversal Host, EntityFramework, etc. Although we can manually load these packages through Nuget, most of these packages are divided very carefully and often introduce many dependencies related packages, resulting in the introduction of seven or eight dlls at any time. Although for design, the granularity division of packages is more reasonable in itself and has no effect on actual functions, for many developers like me who have programming cleanliness behaviors, it is more or less unhappy to see a lot of business-related dlls in the folder.

Maybe Microsoft has also understood our needs and launched the concept of the Yuanbao. A meta package is a NuGet package agreement that describes a set of packages related to meaning. The development team uses dependencies to describe this set of packages. They describe a framework through this set of packages and then selectively publish it. Targeting a framework and implicitly referencing metapackages, this actually adds reference dependencies to each independent package in the metapackage. It can also be used to publish applications.

Using metapackages has the following benefits:

  • It provides a convenient user experience in citing a large number of fine-grained packages.

  • Define a well-tested set of packages (including the various versions specified).

The .NET Core meta packages include:

  • - Some libraries for the .NET Core distribution. That is.NETCoreApp Framework

  • - Contains all supported packages from Core and Entity Framework Core (except packages that contain third-party dependencies).

  • – All supported packages containing third-party dependencies on the basis. (This is not recommended, it is recommended to use)

  • - A set of compatible appearances that enable mscorlib-based portable class libraries (PCLs) to run on .Net Core.

With this foundation, that is, as long as we includeMetapackages can directly use the libraries mentioned above.

The method is very simple, just add it in csproj.

    <ItemGroup>
        <PackageReference Include="" />
    </ItemGroup>

In .net 3.0, FrameworkReference needs to be used instead of PackageReference, the effect is as follows

    <ItemGroup>
        <FrameworkReference Include="" />
    </ItemGroup>

After adding this reference, we can use the extra libraries like in the core program, and we don't need to include those dlls when publishing the program. In fact, these dlls point to those dlls in the .net core SDK without additional release. (This is why PackageReference does not need to specify a version number)

Reference article:

  • Packages, metapackages and frameworks

  • Core's Metapack

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.