简体   繁体   English

Scaffold-DbContext:找不到命令

[英]Scaffold-DbContext: command not found

i try to reverse engnieer my models from an existing database, but the command: Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models我尝试从现有数据库中反向工程我的模型,但命令: Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models doesn´t work. Scaffold-DbContext "Server=(db);Database=xxxx;Trusted_connection=true;" Microsoft.EntityFrameWorkCore.SqlServer -OutputDir Models不起作用。

I get the error message like in the title.我收到标题中的错误消息。

I installed the Nuget packeges :我安装了 Nuget 包:

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

and i don´t know why it doesn´t work.( dotnet ef commands works) I´m sure its a little problem but i can´t find the solution.我不知道为什么它不起作用。( dotnet ef命令有效)我确定这是一个小问题,但我找不到解决方案。 Please help me请帮我

My .csproj:我的.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>

Install Microsoft EntityFrameworkCore tools nuget package in your project by running the following command in Package Manager Console.通过在包管理器控制台中运行以下命令,在项目中安装 Microsoft EntityFrameworkCore 工具 nuget 包。

Install-Package Microsoft.EntityFrameworkCore.Tools -Version 1.1.2

This will install the Cmdlets to run Database first approach via Package Manager Console.这将安装 Cmdlet 以通过包管理器控制台运行数据库优先方法。 For details visit https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/有关详细信息,请访问https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools/

This worked for me这对我有用

use dotnet ef dbcontext scaffold instead of Scaffold-DbContext使用dotnet ef dbcontext scaffold而不是Scaffold-DbContext

for instance例如

dotnet ef dbcontext scaffold "Host=my_host;Database=my_db;Username=my_user;Password=my_pw" Npgsql.EntityFrameworkCore.PostgreSQL -c ContextName -o OutPutFolder 

run dotnet ef dbcontext scaffold -h to see options u can pass !运行dotnet ef dbcontext scaffold -h以查看您可以通过的选项!

Modify the .csproj file to include the following section:修改.csproj文件以包含以下部分:

<ItemGroup>
    <DotNetCliToolReference
        Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
        Version="1.0.0-msbuild3-final" />
</ItemGroup>

This step is only necessary if the .csproj file wasn't automatically modified to add the entry when the Tools package was installed.仅当安装工具包时未自动修改.csproj文件以添加条目时,才需要此步骤。 See https://github.com/aspnet/EntityFramework/issues/7358 .请参阅https://github.com/aspnet/EntityFramework/issues/7358

Restore the packages:恢复软件包:

dotnet restore

Now, check your dotnet ef dbcontext scaffold command.现在,检查您的 dotnet ef dbcontext scaffold 命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 scaffold-DbContext ,命令导致异常:System.Reflection.TargetInvocationException - scaffold-DbContext , command results in exception: System.Reflection.TargetInvocationException Scaffold-DbContext:找不到接受参数“模型”的位置参数 - Scaffold-DbContext : A positional parameter cannot be found that accepts argument 'Models 执行命令“Scaffold-DbContext”时出现错误“ScriptHalted” - When executing the command "Scaffold-DbContext" I get the error "ScriptHalted" 尝试 Scaffold-DbContext 的问题 - Issue trying to Scaffold-DbContext Scaffold-DbContext的替代方案,用于生成实体类型 - Alternatives to Scaffold-DbContext for generating entity types Scaffold-DbContext 忽略构建错误 - Scaffold-DbContext ignores build errors 如何将脚手架 dbcontext 放置到不同的文件夹? - how to scaffold-dbcontext to different folders? -在 Scaffold-DbContext 中无法识别命名空间选项 - -Namespace option is not recognized in Scaffold-DbContext EF Core 脚手架-dbcontext 自定义命名空间 - EF Core scaffold-dbcontext custom namespace 为什么 EF Scaffold-DbContext 命令在报告“未找到设计时服务”后抛出 NRE,当面向 net6.0 时? - Why does the EF Scaffold-DbContext command throw an NRE, after reporting 'No design-time services were found.', when targeting net6.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM