ASP.NET Core 的 AspNetCore 應用程式Microsoft.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. Microsoft.AspNetCore.App安裝.Net Core 3.0 或更新版本的 SDK時,會進行安裝。Microsoft.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.

  • 以 SDK 為目標的專案會 Microsoft.NET.Sdk.Web 隱含地參考 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 套件的任何資產 — ASP.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.

下列專案檔會參考 Microsoft.AspNetCore.App ASP.NET Core 的中繼套件,並代表一般的 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. 如果您對此方法有疑問,請在 Discussion for the Microsoft.AspNetCore.App implicit version (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:專案相依性 AspNetCore。應用程式未包含內含下限。請在相依性版本中包含下限,以確保一致的還原結果。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. 如需詳細資訊,請參閱向前復原 Framework 相依的應用程式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.