Microsoft.AspNetCore.All 元包的优缺点 [英] Pros and cons of Microsoft.AspNetCore.All metapackage

查看:33
本文介绍了Microsoft.AspNetCore.All 元包的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET Core 2.0 中,无需在 .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.

在发布(自包含)应用程序时,将应用 tree-shaking,这意味着:构建过程将找出元包中的哪些包将被使用,并将它们从已发布的文件夹中剥离以保持较小的大小.

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核心运行时存储.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. 当面向 .NET Framework >= 4.6.1 时,您不能使用 Microsoft.AspNetCore.All(或 Microsoft.AspNetCore.App),因为它需要 netcoreapp2.0netcoreapp2.1 分别
  2. 您不能也不应该在可移植类库 (PCL) 中使用它,因为它需要 netcoreapp2.0 并且 PCL 应该针对 netstandard2.0.有一些例外,例如,如果您依赖于仅在 .NET Core 上运行的(ASP.NET Core)包(或者您需要仅 .NET Core API),因为 PCL 针对 netcoreappx.y 无法在 .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 元包的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆