我尝试从现有数据库中反向工程我的模型,但命令:Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models不起作用。

我收到标题中的错误消息。

我安装了 Nuget 包:

Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer.Design

我不知道为什么它不起作用。( dotnet ef 命令有效)
我确定这是一个小问题,但我找不到解决方案。请帮我

我的.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="IdentityServer4">
      <Version>1.5.0</Version>
    </PackageReference>
    <PackageReference Include="IdentityServer4.AccessTokenValidation">
      <Version>1.2.0</Version>
    </PackageReference>
    <PackageReference Include="IdentityServer4.AspNetIdentity">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Identity">
      <Version>1.1.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore">
      <Version>1.1.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore">
      <Version>1.1.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer">
      <Version>1.1.2</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design">
      <Version>1.1.2</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
      <Version>1.1.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup>
      <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
    </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
  </ItemGroup>
</Project>

最佳答案

通过在包管理器控制台中运行以下命令,在项目中安装 Microsoft EntityFrameworkCore 工具 nuget 包。

Install-Package Microsoft.EntityFrameworkCore.Tools -Version 1.1.2
这将安装 Cmdlet 以通过包管理器控制台运行数据库优先方法。详情请访问 https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/

10-06 13:43