【问题标题】:Unable to add API Controller in Visual Studio 2019. Unable to run the selected Code generator, package restore failed无法在 Visual Studio 2019 中添加 API 控制器。无法运行选定的代码生成器,包还原失败
【发布时间】:2021-07-24 14:52:51
【问题描述】:

我正在使用 Visual Studio Community Edition 2019 版本 16.9.4 和 .net core v3.1.14。尝试使用 CRUD 操作构建 API 控制器。收到一条错误消息,显示“无法运行选定的代码生成器。包还原失败。回滚包更改'我检查了 Nuget 包源。已经添加了 EntityFrameworkCore.SqlServer、EntityFrameworkCore 和 EntityFrameworkCore.Design Nuget 包。 下面的屏幕截图捕获了问题的重要细节......

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.14" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.14">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.14" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\PluralSight.Core\PluralSight.Core.csproj" />
    <ProjectReference Include="..\Pluralsight.Data\Pluralsight.Data.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Api\" />
  </ItemGroup>

</Project>

【问题讨论】:

    标签: .net-core entity-framework-core visual-studio-2019


    【解决方案1】:

    您还需要安装 NuGet 包 Microsoft.VisualStudio.Web.CodeGeneration.Design,版本 3.1.5

    编辑: 感谢分享 csproj 文件的内容。我觉得没问题。

    当我安装了不同版本的 EFCore 包时,我发生了这个错误。

    确保您的数据层项目也安装了相同版本的 EFcore 包。

    【讨论】:

    • 添加了包 Microsoft.VisualStudio.Web.CodeGeneration.Design。它仍然显示相同的错误。
    • 你能分享你的csproj文件的内容吗?
    • 我已将我的 csproj 文件的内容添加到问题中
    猜你喜欢
    • 1970-01-01
    • 2016-05-01
    • 2020-09-16
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多