Microsoft.AspNetCore.All元程序包的优缺点

编程入门 行业动态 更新时间:2024-10-23 01:47:31
本文介绍了Microsoft.AspNetCore.All元程序包的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 ASP.NET Core 2.0 中,无需在<$ c $中包括单个包引用。 c> .csproj 文件。 Microsoft.AspNetCore.All 元软件包包含所有必需的软件包。我们可以将该元包包含在 .csproj 文件中,如下所示:

In ASP.NET Core 2.0 there is no need to include individual package references in the .csproj file. Microsoft.AspNetCore.All metapackage contains all the required packages. We can include this metapackage in .csproj file as:

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />

.Net Core应用程序中此元软件包的主要优点和缺点是什么? (还考虑跨平台的自包含应用程序)

What are the main pros and cons of this metapackage in .Net Core applications? (Consider cross platform self contained applications also)

推荐答案

创建针对.NET Core 2.0运行的ASP.NET Core 2.0应用程序时,您应该使用 Microsoft.AspNetCore.All (对于ASP.NET Core 2.1和更高版本, Microsoft.AspNetCore.App 是推荐-从ASP.NET Core 3.0 Microsoft.AspNetCore.All 将被删除),因为这是推荐的方法,对于避免一长串依赖项很有用。

When you create ASP.NET Core 2.0 application running against .NET Core 2.0, you should use Microsoft.AspNetCore.All (for ASP.NET Core 2.1 and higher, Microsoft.AspNetCore.App is recommended - From ASP.NET Core 3.0 Microsoft.AspNetCore.All will be removed) as this is the recommended approach and is useful to avoid a long list of dependencies.

发布(自包含的)应用程序时,将采用摇树方式,这意味着:构建过程将确定将使用元软件包中的哪些软件包并将从发布的文件夹中删除它们以保持较小的大小。

When publishing (self-containing) applications, tree-shaking will be applied, this means: the build process will find out which packages inside the metapackage will be used and will strip them from the published folder to keep the size small.

使用它的另一个原因是。NET Core运行时存储。 Microsoft.AspNetCore.All 包是运行时存储区的一部分,因此不需要发布(如上所述),但更重要的是,它已预先编译,因此可以启动时代也改善了。

Another reason to use it is the .NET Core Runtime Store. The Microsoft.AspNetCore.All package is part of the runtime store so it won't need to be published (as mentioned above) but more importantly, it is precompiled, so startup times improves too.

但是

  • 您不能使用 Microsoft面向.NET Framework> = 4.6.1时的.AspNetCore.All (或 Microsoft.AspNetCore.App ),因为它要求 netcoreapp2.0 和 netcoreapp2.1
  • 您不能也不应使用由于它需要 netcoreapp2.0 而在便携式类库(PCL)中使用,因此PCL应该定位为 netstandard2.0 。有一些例外情况,例如,如果您依赖仅在.NET Core上运行的(ASP.NET Core)程序包(或者您需要仅.NET Core的API),因为针对 netcoreappx.y的PCL 不能在.NET Framework上运行
  • You can't use Microsoft.AspNetCore.All (or Microsoft.AspNetCore.App) when targeting .NET Framework >= 4.6.1, because it requires netcoreapp2.0 and netcoreapp2.1 respectively
  • You can't and shouldn't use it in Portable Class Libraries (PCL) due to the fact that it requires netcoreapp2.0 and PCLs should be targeting netstandard2.0. There are a few exceptions, for example if you depend on a (ASP.NET Core) package which only runs on .NET Core (or you require .NET Core only APIs), since PCLs targeting netcoreappx.y can't run on .NET Framework
  • 更多推荐

    Microsoft.AspNetCore.All元程序包的优缺点

    本文发布于:2023-11-14 15:23:21,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1587810.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:优缺点   程序包   Microsoft   AspNetCore

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!