此平台不支持 System.Data.SqlClient

此平台不支持 System.Data.SqlClient

问题描述:

我将 ASP.NET Core 2 与 Entity Framework Core 2.0.2 一起使用.我在包管理器控制器中创建了一个上下文和 Add-Migrations 命令工作正常.

I'm using ASP.NET Core 2 with Entity Framework Core 2.0.2. I created a context and Add-Migrations command in Package Manager Controller works fine.

但是,当使用 Update-Database 命令时,出现错误:

However when Update-Database command is used, I get an error:

此平台不支持 System.Data.SqlClient

System.Data.SqlClient is not supported on this platform

我不知道问题出在哪里.你能帮助我吗?谢谢.

I can't figure out where the problem is. Can you help me? Thanks.

我的 .csproj 文件:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <DebugType>portable</DebugType>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <DockerComposeProjectPath>..docker-compose.dcproj</DockerComposeProjectPath>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.1" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="2.3.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
  </ItemGroup>

</Project>

几天前我遇到了同样的问题 - 我不确定根本问题是什么,但恢复了一些 EntityFrameworkCore nuget 包回到 2.0.0 似乎已经为我解决了这个问题.这些是我降级的软件包:

I ran into the same issue a couple of days ago - I'm not sure what the underlying issue is, but reverting some of the EntityFrameworkCore nuget packages back to 2.0.0 seems to have resolved the issue for me. These are the packages I downgraded:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />