Microsoft.AspNetCore.App for ASP.NET CoreMicrosoft.AspNetCore.App for ASP.NET Core

ASP.NET Core 共享框架 (Microsoft.AspNetCore.App) 包含由 Microsoft 开发和支持的程序集。The ASP.NET Core shared framework (Microsoft.AspNetCore.App) contains assemblies that are developed and supported by Microsoft. 当安装 NET Core 3.0 或更高版本 SDK 时,安装 Microsoft.AspNetCore.AppMicrosoft.AspNetCore.App is installed when the .NET Core 3.0 or later SDK is installed. 共享框架 是安装在计算机上并包括运行时组件和目标包的一组程序集( .dll 文件)。The shared framework is the set of assemblies (.dll files) that are installed on the machine and includes a runtime component and a targeting pack. 有关详细信息,请参阅共享框架For more information, see The shared framework.

  • 面向 Microsoft.NET.Sdk.Web SDK 的项目隐式引用 Microsoft.AspNetCore.App 框架。Projects that target the Microsoft.NET.Sdk.Web SDK implicitly reference the Microsoft.AspNetCore.App framework.

对于这些项目,不需要其他引用:No additional references are required for these projects:

<Project Sdk="Microsoft.NET.Sdk.Web">

ASP.NET Core 共享框架:The ASP.NET Core shared framework:

  • 不包括第三方依赖项。Doesn't include third-party dependencies.
  • 包括 ASP.NET Core 团队支持的所有包。Includes all supported packages by the ASP.NET Core team.

此功能需要面向 .NET Core 2.x 的 ASP.NET Core 2.x。This feature requires ASP.NET Core 2.x targeting .NET Core 2.x.

适用于 ASP.NET Core 的 Microsoft.AspNetCore.App 元包The Microsoft.AspNetCore.App metapackage for ASP.NET Core:

  • 不包括第三方依赖项,Json.NETRemotion.LinqIX-Async 除外。Does not include third-party dependencies except for Json.NET, Remotion.Linq, and IX-Async. 为确保正常使用主要框架功能,这些第三方依赖项均为必要条件。These 3rd-party dependencies are deemed necessary to ensure the major frameworks features function.
  • 包括 ASP.NET Core 团队支持的所有软件包,包含第三方依赖项的软件包(不包括上文所述)除外。Includes all supported packages by the ASP.NET Core team except those that contain third-party dependencies (other than those previously mentioned).
  • 包括 Entity Framework Core 团队支持的所有软件包,包含第三方依赖项的软件包(不包括上文所述)除外。Includes all supported packages by the Entity Framework Core team except those that contain third-party dependencies (other than those previously mentioned).

Microsoft.AspNetCore.App 包中包含了 ASP.NET Core 2.x 和 Entity Framework Core 2.x 的所有功能。All the features of ASP.NET Core 2.x and Entity Framework Core 2.x are included in the Microsoft.AspNetCore.App package. 面向 ASP.NET Core 2.x 的默认项目模板使用此包。The default project templates targeting ASP.NET Core 2.x use this package. 建议面向 ASP.NET Core 2.x 和 Entity Framework Core 2.x 的应用程序使用 Microsoft.AspNetCore.App 包。We recommend applications targeting ASP.NET Core 2.x and Entity Framework Core 2.x use the Microsoft.AspNetCore.App package.

Microsoft.AspNetCore.App 元包的版本号表示最低 ASP.NET Core 版本和 Entity Framework Core 版本。The version number of the Microsoft.AspNetCore.App metapackage represents the minimum ASP.NET Core version and Entity Framework Core version.

使用 Microsoft.AspNetCore.App 元包可提供用于保护应用的版本限制:Using the Microsoft.AspNetCore.App metapackage provides version restrictions that protect your app:

  • 如果包含的包对 Microsoft.AspNetCore.App 中的包具有可传递的(非直接)依赖项,且这些版本号不同,则 NuGet 将生成错误。If a package is included that has a transitive (not direct) dependency on a package in Microsoft.AspNetCore.App, and those version numbers differ, NuGet will generate an error.
  • 添加到应用的其他包无法更改 Microsoft.AspNetCore.App 中包含的包版本。Other packages added to your app cannot change the version of packages included in Microsoft.AspNetCore.App.
  • 版本一致性能确保可靠的体验。Version consistency ensures a reliable experience. Microsoft.AspNetCore.App 旨在防止在同一应用中结合使用未经测试的相关位版本组合。Microsoft.AspNetCore.App was designed to prevent untested version combinations of related bits being used together in the same app.

使用 Microsoft.AspNetCore.App 元包的应用程序会自动使用 ASP.NET Core 共享框架。Applications that use the Microsoft.AspNetCore.App metapackage automatically take advantage of the ASP.NET Core shared framework. 使用 Microsoft.AspNetCore.App 元包时,应用程序不部署所引用的 ASP.NET Core NuGet 包中的任何资产 — .NET Core 共享框架包含这些资产 。When you use the Microsoft.AspNetCore.App metapackage, no assets from the referenced ASP.NET Core NuGet packages are deployed with the application—the ASP.NET Core shared framework contains these assets. 共享框架中的资产已经过预编译,以便缩短应用程序启动时间。The assets in the shared framework are precompiled to improve application startup time. 有关详细信息,请参阅共享框架For more information, see The shared framework.

以下项目文件为 ASP.NET Core 引用 Microsoft.AspNetCore.App 元包,,它表示一种典型的 ASP.NET Core 2.2 模板:The following project file references the Microsoft.AspNetCore.App metapackage for ASP.NET Core and represents a typical ASP.NET Core 2.2 template:

<Project Sdk="Microsoft.NET.Sdk.Web">


    <PackageReference Include="Microsoft.AspNetCore.App" />


前面的标记表示典型的 ASP.NET Core 2.x 模板。The preceding markup represents a typical ASP.NET Core 2.x template. 它不会为 Microsoft.AspNetCore.App 包引用指定版本号。It doesn't specify a version number for the Microsoft.AspNetCore.App package reference. 如果未指定版本,SDK 会指定隐式版本,即 Microsoft.NET.Sdk.WebWhen the version is not specified, an implicit version is specified by the SDK, that is, Microsoft.NET.Sdk.Web. 建议使用 SDK 指定的隐式版本,而不是在包引用上显式设置版本号。We recommend relying on the implicit version specified by the SDK and not explicitly setting the version number on the package reference. 如果对这种方法有任何疑问,可以在 Microsoft.AspNetCore.App 隐式版本讨论上发表 GitHub 评论。If you have questions on this approach, leave a GitHub comment at the Discussion for the Microsoft.AspNetCore.App implicit version.

对于便携式应用,隐式版本设置为 major.minor.0The implicit version is set to major.minor.0 for portable apps. 共享框架前滚机制将在安装的共享框架的最新兼容版本上运行应用。The shared framework roll-forward mechanism will run the app on the latest compatible version among the installed shared frameworks. 为确保在开发、测试和生产中使用相同的版本,请确保在所有环境中都安装相同版本的共享框架。To guarantee the same version is used in development, test, and production, ensure the same version of the shared framework is installed in all environments. 对于独立应用,将隐式版本号设置为在已安装的 SDK 中捆绑的共享框架的 major.minor.patchFor self contained apps, the implicit version number is set to the major.minor.patch of the shared framework bundled in the installed SDK.

Microsoft.AspNetCore.App 引用上指定版本号,不能保证将选择该共享框架版本 。Specifying a version number on the Microsoft.AspNetCore.App reference does not guarantee that version of the shared framework will be chosen. 例如,假设指定的版本是“2.2.1”,但安装的是“2.2.3”。For example, suppose version "2.2.1" is specified, but "2.2.3" is installed. 这种情况下,应用将使用"2.2.3"。In that case, the app will use "2.2.3". 不过不建议这样做,你可以禁用前滚(修补程序和/或次要版本)。Although not recommended, you can disable roll forward (patch and/or minor). 有关 dotnet 主机前滚以及如何配置其行为的详细信息,请参阅 dotnet 主机前滚For more information regarding dotnet host roll-forward and how to configure its behavior, see dotnet host roll forward.

<Project Sdk 必须设置为 Microsoft.NET.Sdk.Web 以使用隐式版本 Microsoft.AspNetCore.App<Project Sdk must be set to Microsoft.NET.Sdk.Web to use the implicit version Microsoft.AspNetCore.App. 使用 <Project Sdk="Microsoft.NET.Sdk">(不带尾随 .Web)时:When <Project Sdk="Microsoft.NET.Sdk"> (without the trailing .Web) is used:

  • 生成以下警告:The following warning is generated:

    警告 NU1604:项目依赖项 Microsoft.AspNetCore.App 不包括包含下限。请在依赖项版本中包括下限,以确保一致的还原结果。Warning NU1604: Project dependency Microsoft.AspNetCore.App does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results.

  • 这是 .NET Core 2.1 SDK 的一个已知问题。This is a known issue with the .NET Core 2.1 SDK.

更新 ASP.NET CoreUpdate ASP.NET Core

Microsoft.AspNetCore.App元包不是从 NuGet 更新的传统包。The Microsoft.AspNetCore.App metapackage isn't a traditional package that's updated from NuGet. 类似于 Microsoft.NETCore.AppMicrosoft.AspNetCore.App 表示共享运行时,它具有在 NuGet 之外处理的特殊版本控制语义。Similar to Microsoft.NETCore.App, Microsoft.AspNetCore.App represents a shared runtime, which has special versioning semantics handled outside of NuGet. 有关详细信息,请参阅包、元包和框架For more information, see Packages, metapackages and frameworks.

更新 ASP.NET Core:To update ASP.NET Core:

在应用程序重启时,应用程序将前滚到最新安装的版本。Applications will roll forward to the latest installed version on application restart. 无需更新项目文件中的 Microsoft.AspNetCore.App 版本号。It's not necessary to update the Microsoft.AspNetCore.App version number in the project file. 有关详细信息,请参阅依赖于框架的应用会前滚For more information, see Framework-dependent apps roll forward.

如果应用程序之前使用 Microsoft.AspNetCore.All,请参阅从 Microsoft.AspNetCore.All 迁移到 Microsoft.AspNetCore.AppIf your application previously used Microsoft.AspNetCore.All, see Migrating from Microsoft.AspNetCore.All to Microsoft.AspNetCore.App.