Could Not Install Package Microsoft.entityframeworkcore.sqlserver Mac

To install the SQL Server provider, run the following command in the Package Manager Console: Install-Package Microsoft.EntityFrameworkCore.SqlServer To update the provider, use the Update-Package command. To specify a specific version, use the -Version modifier. For example, to install EF Core 2.2.0 packages, append -Version 2.2.0 to the commands. For projects that support PackageReference, copy this XML node into the project file to reference the package. Paket add Microsoft.EntityFrameworkCore -version 3.1.3 The NuGet Team does not provide support for this client.

-->

必备条件Prerequisites

  • EF Core 是一个 .NET Standard 2.0 库。EF Core is a .NET Standard 2.0 library.因此,EF Core 需要支持运行 .NET Standard 2.0 的实现。So EF Core requires a .NET implementation that supports .NET Standard 2.0 to run.其他 .NET Standard 2.0 库也可引用 EF Core。EF Core can also be referenced by other .NET Standard 2.0 libraries.

  • 例如,可使用 EF Core 开发面向 .NET Core 的应用。For example, you can use EF Core to develop apps that target .NET Core.生成 .NET Core 应用需要 .NET Core SDK。Building .NET Core apps requires the .NET Core SDK.还可选择使用 Visual StudioVisual Studio for Mac 或 Visual Studio Code 等开发环境。Optionally, you can also use a development environment like Visual Studio, Visual Studio for Mac, or Visual Studio Code.有关详细信息,请参阅 .NET Core 入门。For more information, check Getting Started with .NET Core.

  • 可在 Windows 上的 Visual Studio 中使用 EF Core 来开发应用程序。You can use EF Core to develop applications on Windows using Visual Studio.建议使用最新版本的 Visual Studio。The latest version of Visual Studio is recommended.

  • EF Core 可以在 Xamarin 和 .NET Native 等其他 .NET 实现上运行。EF Core can run on other .NET implementations like Xamarin and .NET Native.但在实践中,这些实现具有运行时限制,可能会影响 EF Core 处理应用的效率。But in practice those implementations have runtime limitations that may affect how well EF Core works on your app.有关详细信息,请参阅 EF Core 支持的 .NET 实现。For more information, see .NET implementations supported by EF Core.

  • 最后,不同的数据库提供程序可能需要特定的数据库引擎版本、.NET 实现或操作系统。Finally, different database providers may require specific database engine versions, .NET implementations, or operating systems.请确保可用的 EF Core 数据库提供程序支持适用于应用程序的环境。Make sure an EF Core database provider is available that supports the right environment for your application.

获取 Entity Framework Core 运行时Get the Entity Framework Core runtime

要将 EF Core 添加到应用程序,请安装适用于要使用的数据库提供程序的 NuGet 包。To add EF Core to an application, install the NuGet package for the database provider you want to use.

如果要生成 ASP.NET Core 应用程序,不需要安装内存中和 SQL Server 提供程序。If you're building an ASP.NET Core application, you don't need to install the in-memory and SQL Server providers.这些提供程序随 EF Core 运行时一起包含在当前版本的 ASP.NET Core 中。Those providers are included in current versions of ASP.NET Core, alongside the EF Core runtime.

Could Not Install Package Microsoft.entityframeworkcore.sqlserver Mac

要安装或更新 NuGet 包,可以使用 .NET Core 命令行界面 (CLI)、Visual Studio 包管理器对话框或 Visual Studio 包管理器控制台。To install or update NuGet packages, you can use the .NET Core command-line interface (CLI), the Visual Studio Package Manager Dialog, or the Visual Studio Package Manager Console.

.NET Core CLI.NET Core CLI

  • 在操作系统的命令行中使用以下 .NET Core CLI 命令来安装或更新 EF Core SQL Server 提供程序:Use the following .NET Core CLI command from the operating system's command line to install or update the EF Core SQL Server provider:

  • 可以使用 dotnet add package 修饰符在 -v 命令中指明特定的版本。You can indicate a specific version in the dotnet add package command, using the -v modifier.例如,若要安装 EF Core 2.2.0 包,请将 -v 2.2.0 追加到命令中。For example, to install EF Core 2.2.0 packages, append -v 2.2.0 to the command.

有关详细信息,请参阅 .NET 命令行接口 (CLI) 工具。For more information, see .NET command-line interface (CLI) tools.

Visual Studio NuGet 包管理器对话框Visual Studio NuGet Package Manager Dialog

  • 从 Visual Studio 菜单中选择“项目”>“管理 NuGet 包” From the Visual Studio menu, select Project > Manage NuGet Packages

  • 单击“浏览”或“更新”选项卡 Click on the Browse or the Updates tab

  • 若要安装或更新 SQL Server 提供程序,请选择 Microsoft.EntityFrameworkCore.SqlServer 包并确认。To install or update the SQL Server provider, select the Microsoft.EntityFrameworkCore.SqlServer package, and confirm.

有关详细信息,请参阅 NuGet 包管理器对话框。For more information, see NuGet Package Manager Dialog.

Visual Studio NuGet 包管理器控制台Visual Studio NuGet Package Manager Console

  • 从 Visual Studio 菜单中选择“工具”>“NuGet 包管理器”>“包管理器控制台” From the Visual Studio menu, select Tools > NuGet Package Manager > Package Manager Console

  • 若要安装 SQL Server 提供程序,请在包管理器控制台中运行以下命令:To install the SQL Server provider, run the following command in the Package Manager Console:

  • 若要更新提供程序,使用 Update-Package 命令。To update the provider, use the Update-Package command.

  • 若要指定特定版本,可以使用 -Version 修饰符。To specify a specific version, use the -Version modifier.例如,若要安装 EF Core 2.2.0 包,请将 -Version 2.2.0 追加到命令中For example, to install EF Core 2.2.0 packages, append -Version 2.2.0 to the commands

有关详细信息,请参阅包管理器控制台。For more information, see Package Manager Console.

获取 Entity Framework Core 工具Get the Entity Framework Core tools

可以安装工具来执行项目中与 EF Core 相关的任务,例如创建和应用数据库迁移,或基于现有数据库创建 EF Core 模型。You can install tools to carry out EF Core-related tasks in your project, like creating and applying database migrations, or creating an EF Core model based on an existing database.

提供了两个工具集:Two sets of tools are available:

  • .NET Core 命令行接口 (CLI) 工具可用于 Windows、Linux 或 macOS。The .NET Core command-line interface (CLI) tools can be used on Windows, Linux, or macOS.这些命令以 dotnet ef 开头。These commands begin with dotnet ef.

  • 包管理器控制台 (PMC) 工具在 Windows 上的 Visual Studio 中运行。The Package Manager Console (PMC) tools run in Visual Studio on Windows.这些命令以动词开头,例如 Add-MigrationUpdate-DatabaseThese commands start with a verb, for example Add-Migration, Update-Database.

虽然也可在包管理器控制台中使用 dotnet ef 命令,但在使用 Visual Studio 时建议使用包管理器控制台工具:Although you can also use the dotnet ef commands from the Package Manager Console, it's recommended to use the Package Manager Console tools when you're using Visual Studio:

  • 它们会自动使用在 Visual Studio 的 PMC 中选择的当前项目,无需手动切换目录。They automatically work with the current project selected in the PMC in Visual Studio, without requiring manually switching directories.

  • 命令完成后,它们会自动在 Visual Studio 中打开命令所生成的文件。They automatically open files generated by the commands in Visual Studio after the command is completed.

获取 .NET Core CLI 工具Get the .NET Core CLI tools

.NET core CLI 工具需要前面的系统必备中提到的 .NET Core SDK。.NET Core CLI tools require the .NET Core SDK, mentioned earlier in Prerequisites.

dotnet ef 命令包含在当前版本的 .NET Core SDK 中,但若要对特定命令启用该命令,必须安装 Microsoft.EntityFrameworkCore.Design 包:The dotnet ef commands are included in current versions of the .NET Core SDK, but to enable the commands on a specific project, you have to install the Microsoft.EntityFrameworkCore.Design package:

重要

请务必使用与运行时包主版本匹配的工具包版本。Always use the version of the tools package that matches the major version of the runtime packages.

获取包管理器控制台工具Get the Package Manager Console tools

若要获取适用于 EF Core 的包管理器控制台工具,请安装 Microsoft.EntityFrameworkCore.Tools 包。To get the Package Manager Console tools for EF Core, install the Microsoft.EntityFrameworkCore.Tools package.例如,在 Visual Studio 中:For example, from Visual Studio:

ASP.NET Core 应用自动随附此包。For ASP.NET Core apps, this package is included automatically.

升级到最新版本的 EF CoreUpgrading to the latest EF Core

  • 每次发布新版本的 EF Core 时,我们都还会在 EF Core 项目中发布新版本的提供程序,如 Microsoft.EntityFrameworkCore.SqlServer、Microsoft.EntityFrameworkCore.Sqlite 和 Microsoft.EntityFrameworkCore.InMemory。Any time we release a new version of EF Core, we also release a new version of the providers that are part of the EF Core project, like Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Sqlite, and Microsoft.EntityFrameworkCore.InMemory.只需升级到新版本的提供程序即可获取所有改进。You can just upgrade to the new version of the provider to get all the improvements.

  • EF Core 以及 SQL Server 和内存中提供程序包含在当前版本的 ASP.NET Core 中。EF Core, together with the SQL Server and the in-memory providers are included in current versions of ASP.NET Core.若要将现有 ASP.NET Core 应用程序升级到较新版本的 EF Core,请务必升级 ASP.NET Core 的版本。To upgrade an existing ASP.NET Core application to a newer version of EF Core, always upgrade the version of ASP.NET Core.

  • 如需更新使用第三方数据库提供程序的应用程序,请始终检查与要使用的 EF Core 版本兼容的提供程序有无更新。If you need to update an application that is using a third-party database provider, always check for an update of the provider that is compatible with the version of EF Core you want to use.例如,早期版本的数据库提供程序不兼容 2.0 版 EF Core 运行时。For example, database providers for previous versions are not compatible with version 2.0 of the EF Core runtime.

  • 用于 EF Core 的第三方提供程序通常不随 EF Core 运行发布修补程序版本。Third-party providers for EF Core usually don't release patch versions alongside the EF Core runtime.若要将使用第三方提供程序的应用程序升级到 EF Core 的修补程序版本,可能需要添加对单独的 EF Core 运行时组件(如 Microsoft.EntityFrameworkCore 和 Microsoft.EntityFrameworkCore.Relational)的直接引用。To upgrade an application that uses a third-party provider to a patch version of EF Core, you may need to add a direct reference to individual EF Core runtime components, such as Microsoft.EntityFrameworkCore, and Microsoft.EntityFrameworkCore.Relational.

  • 若要将现有应用程序升级到最新版本的 EF Core,可能需要手动删除一些对旧版 EF Core 包的引用:If you're upgrading an existing application to the latest version of EF Core, some references to older EF Core packages may need to be removed manually:

    • EF Core 2.0 及更高版本不再需要或支持 Microsoft.EntityFrameworkCore.SqlServer.Design 等数据库提供程序设计时包,但在升级其他包后,它们不会被自动删除。Database provider design-time packages such as Microsoft.EntityFrameworkCore.SqlServer.Design are no longer required or supported from EF Core 2.0 and later, but aren't automatically removed when upgrading the other packages.

    • 自版本 2.1 起的 .NET SDK 包含 .NET CLI 工具,这样就可以从项目文件中删除对相应包的引用:The .NET CLI tools are included in the .NET SDK since version 2.1, so the reference to that package can be removed from the project file:

-->

Prerequisites

Could Not Install Package Microsoft.entityframeworkcore.sqlserver Machine

  • EF Core is a .NET Standard 2.0 library. So EF Core requires a .NET implementation that supports .NET Standard 2.0 to run. EF Core can also be referenced by other .NET Standard 2.0 libraries.

  • For example, you can use EF Core to develop apps that target .NET Core. Building .NET Core apps requires the .NET Core SDK. Optionally, you can also use a development environment like Visual Studio, Visual Studio for Mac, or Visual Studio Code. For more information, check Getting Started with .NET Core.

  • You can use EF Core to develop applications on Windows using Visual Studio. The latest version of Visual Studio is recommended.

  • EF Core can run on other .NET implementations like Xamarin and .NET Native. But in practice those implementations have runtime limitations that may affect how well EF Core works on your app. For more information, see .NET implementations supported by EF Core.

  • Finally, different database providers may require specific database engine versions, .NET implementations, or operating systems. Make sure an EF Core database provider is available that supports the right environment for your application.

Could Not Install Package Microsoft.entityframeworkcore.sqlserver Mac Os

Get the Entity Framework Core runtime

To add EF Core to an application, install the NuGet package for the database provider you want to use.

If you're building an ASP.NET Core application, you don't need to install the in-memory and SQL Server providers. Those providers are included in current versions of ASP.NET Core, alongside the EF Core runtime.

Could Not Install Package Microsoft.entityframeworkcore.sqlserver Macbook Pro

To install or update NuGet packages, you can use the .NET Core command-line interface (CLI), the Visual Studio Package Manager Dialog, or the Visual Studio Package Manager Console.

.NET Core CLI

  • Use the following .NET Core CLI command from the operating system's command line to install or update the EF Core SQL Server provider:

  • You can indicate a specific version in the dotnet add package command, using the -v modifier. For example, to install EF Core 2.2.0 packages, append -v 2.2.0 to the command.

For more information, see .NET command-line interface (CLI) tools.

Visual Studio NuGet Package Manager Dialog

  • From the Visual Studio menu, select Project > Manage NuGet Packages

  • Click on the Browse or the Updates tab

  • To install or update the SQL Server provider, select the Microsoft.EntityFrameworkCore.SqlServer package, and confirm.

For more information, see NuGet Package Manager Dialog.

Visual Studio NuGet Package Manager Console

  • From the Visual Studio menu, select Tools > NuGet Package Manager > Package Manager Console

  • To install the SQL Server provider, run the following command in the Package Manager Console:

  • To update the provider, use the Update-Package command.

  • To specify a specific version, use the -Version modifier. For example, to install EF Core 2.2.0 packages, append -Version 2.2.0 to the commands

For more information, see Package Manager Console.

Get the Entity Framework Core tools

You can install tools to carry out EF Core-related tasks in your project, like creating and applying database migrations, or creating an EF Core model based on an existing database.

Two sets of tools are available:

  • The .NET Core command-line interface (CLI) tools can be used on Windows, Linux, or macOS. These commands begin with dotnet ef.

  • The Package Manager Console (PMC) tools run in Visual Studio on Windows. These commands start with a verb, for example Add-Migration, Update-Database.

Although you can also use the dotnet ef commands from the Package Manager Console, it's recommended to use the Package Manager Console tools when you're using Visual Studio:

  • They automatically work with the current project selected in the PMC in Visual Studio, without requiring manually switching directories.

  • They automatically open files generated by the commands in Visual Studio after the command is completed.

Get the .NET Core CLI tools

.NET Core CLI tools require the .NET Core SDK, mentioned earlier in Prerequisites.

The dotnet ef commands are included in current versions of the .NET Core SDK, but to enable the commands on a specific project, you have to install the Microsoft.EntityFrameworkCore.Design package:

Important

Could Not Install Package Microsoft.entityframeworkcore.sqlserver Mac Pro

Always use the version of the tools package that matches the major version of the runtime packages.

Get the Package Manager Console tools

To get the Package Manager Console tools for EF Core, install the Microsoft.EntityFrameworkCore.Tools package. For example, from Visual Studio:

Not

For ASP.NET Core apps, this package is included automatically.

Upgrading to the latest EF Core

  • Any time we release a new version of EF Core, we also release a new version of the providers that are part of the EF Core project, like Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Sqlite, and Microsoft.EntityFrameworkCore.InMemory. You can just upgrade to the new version of the provider to get all the improvements.

  • EF Core, together with the SQL Server and the in-memory providers are included in current versions of ASP.NET Core. To upgrade an existing ASP.NET Core application to a newer version of EF Core, always upgrade the version of ASP.NET Core.

  • If you need to update an application that is using a third-party database provider, always check for an update of the provider that is compatible with the version of EF Core you want to use. For example, database providers for previous versions are not compatible with version 2.0 of the EF Core runtime.

  • Third-party providers for EF Core usually don't release patch versions alongside the EF Core runtime. To upgrade an application that uses a third-party provider to a patch version of EF Core, you may need to add a direct reference to individual EF Core runtime components, such as Microsoft.EntityFrameworkCore, and Microsoft.EntityFrameworkCore.Relational.

  • If you're upgrading an existing application to the latest version of EF Core, some references to older EF Core packages may need to be removed manually:

    • Database provider design-time packages such as Microsoft.EntityFrameworkCore.SqlServer.Design are no longer required or supported from EF Core 2.0 and later, but aren't automatically removed when upgrading the other packages.

    • The .NET CLI tools are included in the .NET SDK since version 2.1, so the reference to that package can be removed from the project file: