Unable to add API Controller in Visual Studio 2019. Unable to run the selected Code generator, package restore failed

Viewed 269

I am using Visual Studio Community Edition 2019 ver 16.9.4 and .net core v3.1.14. Trying to scaffold an API Controller with CRUD operations. Get an error that says "Unable to run the selected code generator. Package restore failed. Rolling back package changes for ' I checked the Nuget package sources. Have already added the EntityFrameworkCore.SqlServer, EntityFrameworkCore and EntityFrameworkCore.Design Nuget packages. Below screen grab captures the vital details of the issue...

enter image description here

<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>
1 Answers

You also need to install the NuGet package Microsoft.VisualStudio.Web.CodeGeneration.Design, version 3.1.5

Edit: Thanks for sharing contents of csproj file. Looks all right to me.

This error occurred for me when I had different versions of the EFCore package installed.

Make sure that your data layer project also has the same versions of EFcore packages installed.

Related