Entity Framework Core 工具Entity Framework Core Tools

Entity Framework Core 工具可在 EF Core 應用程式開發期間協助您。The Entity Framework Core Tools help you during the development of EF Core apps. 它們主要用來將資料庫結構描述反向工程以支援 DbContext 和實體類型,以及管理「移轉」。They're primarily used to scaffold a DbContext and entity types by reverse engineering the schema of a database, and to manage Migrations.

EF Core 套件管理員主控台 (PMC) 工具提供 Visual Studio 內的更好經驗。The EF Core Package Manager Console (PMC) Tools provide a superior experience inside Visual Studio. 使用 NuGet 的套件管理員主控台來執行它們。Run them using NuGet's Package Manager Console. 這些工具會使用 .NET Framework 和 .NET Core 專案。These tools work with both .NET Framework and .NET Core projects.

EF Core .NET 命令列工具.NET Core 命令列介面 (CLI) 工具的延伸模組,而後者跨平台,而且可以在 Visual Studio 外部執行。The EF Core .NET Command-line Tools are an extension to the .NET Core command-line interface (CLI) tools that are cross-platform and can run outside of Visual Studio. 這些工具需要 .NET Core SDK 專案 (專案檔中含 Sdk="Microsoft.NET.Sdk" 或類似項目的專案)。These tools require a .NET Core SDK project (one with Sdk="Microsoft.NET.Sdk" or similar in the project file).

這兩個工具都會公開相同的功能。Both tools expose the same functionality. 如果您要在 Visual Studio 中進行開發,則建議使用 PMC 工具,因為它們提供更加整合的體驗。If you're developing in Visual Studio, we recommend using the PMC Tools since they provide a more integrated experience.


這些工具還支援目標設為 .NET Framework 或 .NET Core 的專案。The tools support projects targeting .NET Framework or .NET Core.

若您想要使用類別程式庫,請在可行的情況下使用 .NET Core 或 .NET Framework 類別程式庫。If you want to use a class library, then consider using a .NET Core or .NET Framework class library if possible. 這會使 .NET 工具產生較少問題。This will result in the least issues with .NET tooling. 而如果您想要使用 .NET Standard 類別程式庫,則需要以 .NET Framework 或 .Net Core 為目標的啟動專案,使工具擁有具體的目標平台來上傳您的類別程式庫。If instead you wish to use a .NET Standard class library, then you will need to use a startup project that targets .NET Framework or .NET Core so that the tooling has a conrete target platform into which it can load your class library. 您可使用實際沒有程式碼的虛設專案作為啟動專案,此專案的目的僅是為工具提供目標。This startup project can be a dummy project with no real code--it is only needed to provide a target for the tooling.

若您的專案將另一個架構設為目標 (例如通用 Windows 或 Xamarin),則必須建立個別的 .NET Standard 類別程式庫。If your project targets another framework (for example, Universal Windows or Xamarin), then you will need to create a separate .NET Standard class library. 在此情況下,請遵循上述指導,並建立可供工具使用的啟動專案。In this case, follow the guidance above to also create a startup project that can be used by the tooling.

啟始和目標專案Startup and Target Projects

只要您叫用命令,就會包含兩個專案:目標專案和啟始專案。Whenever you invoke a command, there are two projects involved: the target project and the startup project.

目標專案就是新增 (在某些情況下會移除) 任何檔案的位置。The target project is where any files are added (or in some cases removed).

啟始專案是工具在執行您的專案程式碼時所模擬的專案。The startup project is the one emulated by the tools when executing your project's code.

目標專案和啟始專案可以相同。Both the target project and the startup project can be the same.