本文介绍了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.

使用它的另一个原因是。 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.

但是


  1. 您不能使用 Microsoft面向.NET Framework> = 4.6.1时的.AspNetCore.All (或 Microsoft.AspNetCore.App ),因为它要求 netcoreapp2.0 netcoreapp2.1

  2. 您不能也不应使用由于它需要 netcoreapp2.0 而在便携式类库(PCL)中使用,因此PCL应该定位为 netstandard2.0 。有一些例外情况,例如,如果您依赖仅在.NET Core上运行的(ASP.NET Core)程序包(或者您需要仅.NET Core的API),因为针对 netcoreappx.y的PCL 不能在.NET Framework上运行

  1. 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
  2. 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元程序包的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:18