【问题标题】:Dot Net core- Generate code for entity issueDot Net core - 为实体问题生成代码
【发布时间】:2020-07-08 11:28:12
【问题描述】:

我有一个项目在同一个解决方案资源管理器

中包含两个项目

第一个:DbModelContextProvider(类库)

第二个:AppApiProvider(MVC核心api -v3.1.4)

我想创建一个控制器API Controller with actions, using Entity Framework自动生成代码系统Nuget但是不能生成有错误

错误:there was an error running the selected code generator package restore failed rolling back pachage change for 'AppApiProvider'

我已经安装了Install-Package Microsoft.EntityFrameworkCore.Design -Version 3.1.4,但没有修复

然后在报价前搜索我的问题,但没有解决你的问题。 Quotation old

在startup.cs AppApiProvider项目中添加ConnectionString,并在appsettings.json中插入CS但不修复

startup.cs

services.AddDbContext<DB_iServiceContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

在 AppDbContext 中设置 connectionString OnConfiguring(DbContextOptionsBuilder optionsBuilder)

optionsBuilder.UseSqlServer("myConStr)

AppApiProvider.csproj

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\DbModelContextProvider\DbModelContextProvider.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.6.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.6.0" />
    <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="3.0.51" />
    <PackageReference Include="ZJA.Protection.Core" Version="1.0.0" />
  </ItemGroup>


</Project>

【问题讨论】:

  • 您好,能否分享一下您的.csproj文件(双击您的项目名称,会打开.csproj文件)?这个错误可能是版本错误造成的。
  • 请查看我的报价更新

标签: c# asp.net-core-mvc class-library ef-core-3.0


【解决方案1】:

那是因为Microsoft.EntityFrameworkCore.Design的版本与其他包不匹配。将版本从3.1.4更改为3.1.5:

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

更新:

<ItemGroup>
   <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.4" />
   <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.5" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
     <PrivateAssets>all</PrivateAssets>
     <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.6.0" />
   <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
   <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.6.0" />
   <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="3.0.51" />
   <PackageReference Include="ZJA.Protection.Core" Version="1.0.0" />
</ItemGroup>

【讨论】:

  • 我知道。但是当你使用脚手架工具时,它会自动下载最新版本(3.1.5)的Microsoft.EntityFrameworkCore.Tools包,Microsoft.EntityFrameworkCore.SqlServer包等等。它们与你的不匹配3.1.4版本Microsoft.EntityFrameworkCore.Design包。
  • 如果我的模型用class library 唤醒,如果我的模型在项目 api 中的初始化没有问题,亲爱的
  • 不确定原因,我认为应该是设计的,你可以在github上问。解决方案是否帮助你解决了你的问题?
  • 嗨,还没有修复
  • 尝试像我更新的那样替换你的 csproj 文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-11
  • 2017-08-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-15
  • 1970-01-01
  • 2012-09-13
相关资源
最近更新 更多